comm.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef __COMM_H
  2. #define __COMM_H
  3. #include <string>
  4. #include <sstream>
  5. #include <cstdio>
  6. #include <vector>
  7. #include <cstring>
  8. #include <cmath>
  9. #include<iostream>
  10. #include <fstream>
  11. #include <algorithm>
  12. using namespace std;
  13. #define EVENT_ACCESSAUTH_SUCCEED 0x50200001 // 准入成功
  14. #define EVENT_ACCESSAUTH_FAILED 0x50280002 // 准入失败
  15. #define EVENT_ACCESSAUTH_TIMEOUT 0x50280003 // 准入超时
  16. #define EVENT_MOD_INITIALIZER_MK_LOADED 0x50900001 // 主密钥初始化成功
  17. #define EVENT_MOD_INITIALIZER_MK_FAILED 0x50980002 // 主密钥初始化失败
  18. #define PUKFILENAME_RSA "RVCPubKey.ini"
  19. #define PUKFILENAME_SM2 "RVCSM2PubKey.ini"
  20. #define PFKEYFILENAME_DES "CMBRVCKeys.dat"
  21. #define PFKEYFILENAME_SM4 "CMBRVCSm4Keys.dat"
  22. typedef unsigned char BYTE;
  23. void GetNewForm(const char* form, char* newForm);
  24. string GetOutPutStr(const char* form, ...);
  25. int no_begin_with(const char strA[], const char strB[]);
  26. int str2int(const string str, int& ret);
  27. int str2int(const string str);
  28. vector<string> split_str(string strA, string strB);
  29. int ip2byte(const string str, BYTE ip[]);
  30. char* Hex2Str(const char* src, int& dstLen);
  31. char* Str2Hex(const char* str, int strLen);
  32. #ifdef __linux__
  33. #define RUNTIME_PATH "/opt/run/runinfo/runcfg"
  34. #include <sys/types.h>
  35. #include <ifaddrs.h>
  36. #include <netinet/in.h>
  37. #include <arpa/inet.h>
  38. #include <unistd.h>
  39. int getIPFromLinux(char* ip);
  40. bool get_cpu_id_by_asm(std::string & cpu_id);
  41. bool get_cpu_id_by_system(std::string& cpu_id, const string save_path = RUNTIME_PATH);
  42. bool get_board_serial_by_system(std::string& board_serial, const string save_path = RUNTIME_PATH);
  43. bool get_disk_serial_by_system(std::vector<string>& serial_no, int& errCode, const string save_path = RUNTIME_PATH);
  44. bool file_is_exist(string filePath);
  45. bool dir_is_exist(string dirPath);
  46. int file_create(string filePath);
  47. int dir_create(string dirPath);
  48. int remove_file(string filePath);
  49. int remove_dir(string dirPath);
  50. #include<sys/time.h>
  51. #include <time.h>
  52. typedef struct {
  53. int year;
  54. int month;
  55. int day;
  56. int hour;
  57. int minute;
  58. int second;
  59. } TIME;
  60. bool set_system_time(TIME * _time);
  61. extern "C" bool set_system_time_by_sec(int sec);
  62. TIME* get_system_time();
  63. string time2str(const TIME * tim);
  64. TIME* str2time(string str);
  65. #endif //__linux__
  66. #endif // !__COMM_H