|
@@ -3,11 +3,12 @@
|
|
|
#include "com_IPMIDefs.h"
|
|
|
#include "ResultUtils.h"
|
|
|
#include "cJSON.h"
|
|
|
+#include <string.h>
|
|
|
/*获取设备信息*/
|
|
|
|
|
|
/*获取设备信息*/
|
|
|
void getDeviceInfo(Webs *wp){
|
|
|
- logmsg(2, "--------------------ggggggggg----------------");
|
|
|
+ // logmsg(2, "--------------------ggggggggg----------------");
|
|
|
|
|
|
uint16_t wRet = LIBIPMI_E_SUCCESS;
|
|
|
GetDevIDRes_T DeviceID;
|
|
@@ -15,91 +16,93 @@ void getDeviceInfo(Webs *wp){
|
|
|
int sock;
|
|
|
struct sockaddr_in *myaddr;
|
|
|
|
|
|
- char BuildTime[30] = {0};
|
|
|
- char FwVersion[10] = {0};
|
|
|
+ char BuildTime[30] = "2020-111";
|
|
|
+ char FwVersion[10] = "1.1111";
|
|
|
char MacAddr[18] = {0};
|
|
|
char IpAddr[16] = {0};
|
|
|
|
|
|
|
|
|
- //Create session
|
|
|
- LIBIPMI_CreateSession(&wp->ipmi_session, 10);
|
|
|
-
|
|
|
- //get build time
|
|
|
- sprintf(BuildTime, "%s %s", __DATE__, __TIME__);
|
|
|
-
|
|
|
- //get firmware version
|
|
|
- wRet = IPMICMD_GetDeviceID( &wp->ipmi_session, &DeviceID, DEFAULT_TIMEOUT);
|
|
|
- if (wRet == LIBIPMI_E_SUCCESS)
|
|
|
- {
|
|
|
- sprintf(FwVersion, "%d.%d", DeviceID.FirmwareRevision1, DeviceID.FirmwareRevision2);
|
|
|
- }
|
|
|
-
|
|
|
- //get mac address
|
|
|
- if((sock=socket(AF_INET,SOCK_STREAM,0))<0)
|
|
|
- {
|
|
|
- printf("Get mac address socket fail!\n");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- strcpy(ifreq.ifr_name,"eth0");
|
|
|
- if(ioctl(sock,SIOCGIFHWADDR,&ifreq)<0)
|
|
|
- {
|
|
|
- printf("Get mac address ioctl fail!\n");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- sprintf(MacAddr, "%02x:%02x:%02x:%02x:%02x:%02x\n",
|
|
|
- (unsigned char)ifreq.ifr_hwaddr.sa_data[0],
|
|
|
- (unsigned char)ifreq.ifr_hwaddr.sa_data[1],
|
|
|
- (unsigned char)ifreq.ifr_hwaddr.sa_data[2],
|
|
|
- (unsigned char)ifreq.ifr_hwaddr.sa_data[3],
|
|
|
- (unsigned char)ifreq.ifr_hwaddr.sa_data[4],
|
|
|
- (unsigned char)ifreq.ifr_hwaddr.sa_data[5]);
|
|
|
- }
|
|
|
- }
|
|
|
- close(sock);
|
|
|
-
|
|
|
- //get ip address
|
|
|
- strcpy(ifreq.ifr_name, "eth0");
|
|
|
- if((sock=socket(AF_INET, SOCK_STREAM, 0))<0)
|
|
|
- {
|
|
|
- printf("Get ip address socket fail!\n");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- wRet = ioctl(sock, SIOCGIFADDR, &ifreq);
|
|
|
- if(wRet < 0)
|
|
|
- {
|
|
|
- printf("Get ip address ioctl fail!\n");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- myaddr = (struct sockaddr_in *)&(ifreq.ifr_addr);
|
|
|
- strcpy(IpAddr, inet_ntoa(myaddr->sin_addr));
|
|
|
- }
|
|
|
- }
|
|
|
- close(sock);
|
|
|
+ // //Create session
|
|
|
+ // LIBIPMI_CreateSession(&wp->ipmi_session, 10);
|
|
|
+
|
|
|
+ // //get build time
|
|
|
+ // sprintf(BuildTime, "%s %s", __DATE__, __TIME__);
|
|
|
+
|
|
|
+ // //get firmware version
|
|
|
+ // wRet = IPMICMD_GetDeviceID( &wp->ipmi_session, &DeviceID, DEFAULT_TIMEOUT);
|
|
|
+ // if (wRet == LIBIPMI_E_SUCCESS)
|
|
|
+ // {
|
|
|
+ // sprintf(FwVersion, "%d.%d", DeviceID.FirmwareRevision1, DeviceID.FirmwareRevision2);
|
|
|
+ // }
|
|
|
+
|
|
|
+ // //get mac address
|
|
|
+ // if((sock=socket(AF_INET,SOCK_STREAM,0))<0)
|
|
|
+ // {
|
|
|
+ // printf("Get mac address socket fail!\n");
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // strcpy(ifreq.ifr_name,"eth0");
|
|
|
+ // if(ioctl(sock,SIOCGIFHWADDR,&ifreq)<0)
|
|
|
+ // {
|
|
|
+ // printf("Get mac address ioctl fail!\n");
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // sprintf(MacAddr, "%02x:%02x:%02x:%02x:%02x:%02x\n",
|
|
|
+ // (unsigned char)ifreq.ifr_hwaddr.sa_data[0],
|
|
|
+ // (unsigned char)ifreq.ifr_hwaddr.sa_data[1],
|
|
|
+ // (unsigned char)ifreq.ifr_hwaddr.sa_data[2],
|
|
|
+ // (unsigned char)ifreq.ifr_hwaddr.sa_data[3],
|
|
|
+ // (unsigned char)ifreq.ifr_hwaddr.sa_data[4],
|
|
|
+ // (unsigned char)ifreq.ifr_hwaddr.sa_data[5]);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // close(sock);
|
|
|
+
|
|
|
+ // //get ip address
|
|
|
+ // strcpy(ifreq.ifr_name, "eth0");
|
|
|
+ // if((sock=socket(AF_INET, SOCK_STREAM, 0))<0)
|
|
|
+ // {
|
|
|
+ // printf("Get ip address socket fail!\n");
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // wRet = ioctl(sock, SIOCGIFADDR, &ifreq);
|
|
|
+ // if(wRet < 0)
|
|
|
+ // {
|
|
|
+ // printf("Get ip address ioctl fail!\n");
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // myaddr = (struct sockaddr_in *)&(ifreq.ifr_addr);
|
|
|
+ // strcpy(IpAddr, inet_ntoa(myaddr->sin_addr));
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // close(sock);
|
|
|
|
|
|
- //Close session
|
|
|
- LIBIPMI_CloseSession(&wp->ipmi_session );
|
|
|
+ // //Close session
|
|
|
+ // LIBIPMI_CloseSession(&wp->ipmi_session );
|
|
|
|
|
|
printf("BuildTime: %s\n", BuildTime);
|
|
|
printf("FwVersion: %s\n", FwVersion);
|
|
|
printf("MacAddr: %s\n", MacAddr);
|
|
|
printf("IpAddr: %s\n", IpAddr);
|
|
|
|
|
|
- cchar *pStr;
|
|
|
- int code = 200;
|
|
|
- cJSON * root = cJSON_CreateObject();
|
|
|
- cJSON * data = cJSON_CreateObject();
|
|
|
- // cJSON * next = cJSON_CreateObject();
|
|
|
- cJSON_AddItemToObject(root, "data", data);//根节点下添加
|
|
|
- cJSON_AddItemToObject(root, "msg", cJSON_CreateString(""));
|
|
|
- cJSON_AddItemToObject(root, "code", cJSON_CreateString("200"));
|
|
|
- cJSON_AddStringToObject(data, "BuildTime", BuildTime);
|
|
|
- cJSON_AddStringToObject(data, "FwVersion", FwVersion);
|
|
|
-
|
|
|
- pStr = cJSON_Print(root);
|
|
|
+ char *pStr;
|
|
|
+ pStr = malloc(200);
|
|
|
+ sprintf(pStr, "{\n\"data\": {\n},\n\"msg\": %s\n%s \"Not Found\",\n \"code\": 404\n}", BuildTime, FwVersion);
|
|
|
+ // int code = 200;
|
|
|
+ // cJSON * root = cJSON_CreateObject();
|
|
|
+ // cJSON * data = cJSON_CreateObject();
|
|
|
+ // // cJSON * next = cJSON_CreateObject();
|
|
|
+ // cJSON_AddItemToObject(root, "data", data);//根节点下添加
|
|
|
+ // cJSON_AddItemToObject(root, "msg", cJSON_CreateString(""));
|
|
|
+ // cJSON_AddItemToObject(root, "code", cJSON_CreateString("200"));
|
|
|
+ // cJSON_AddStringToObject(data, "BuildTime", BuildTime);
|
|
|
+ // cJSON_AddStringToObject(data, "FwVersion", FwVersion);
|
|
|
+
|
|
|
+ // pStr = cJSON_Print(root);
|
|
|
|
|
|
printf("first json:\n%s\n", pStr);
|
|
|
logmsg(2, "-----------------------jso1n----------------------%s", pStr);
|
|
@@ -108,7 +111,7 @@ void getDeviceInfo(Webs *wp){
|
|
|
websWriteHeaders(wp, -1, 0);
|
|
|
websWriteEndHeaders(wp);
|
|
|
//websWrite(wp, "[");
|
|
|
- websWrite(wp, " {\"name\":\"jimbo\"}");
|
|
|
+ websWrite(wp, pStr);
|
|
|
//websWrite(wp, "]");
|
|
|
//websFlush(wp, 0);
|
|
|
websDone(wp);
|
|
@@ -120,39 +123,38 @@ void getDeviceInfo(Webs *wp){
|
|
|
|
|
|
/*获取设备信息*/
|
|
|
void getDeviceInfoBak(Webs *wp){
|
|
|
- logmsg(2, "--------------------ggggggggg----------------");
|
|
|
-
|
|
|
- uint16_t wRet = LIBIPMI_E_SUCCESS;
|
|
|
- GetDevIDRes_T DeviceID;
|
|
|
- char BuildTime[30] = {0};
|
|
|
- char FwVersion[10] = {0};
|
|
|
- //Create session
|
|
|
- LIBIPMI_CreateSession(&wp->ipmi_session, 10);
|
|
|
- sprintf(BuildTime, "%s %s", __DATE__, __TIME__);
|
|
|
- wRet = IPMICMD_GetDeviceID( &wp->ipmi_session, &DeviceID, DEFAULT_TIMEOUT);
|
|
|
- if (wRet == LIBIPMI_E_SUCCESS)
|
|
|
- {
|
|
|
- sprintf(FwVersion, "%d.%d", DeviceID.FirmwareRevision1, DeviceID.FirmwareRevision2);
|
|
|
- }
|
|
|
- printf("BuildTime: %s\n", BuildTime);
|
|
|
- printf("FwVersion: %s\n", FwVersion);
|
|
|
- //Close session
|
|
|
- LIBIPMI_CloseSession(&wp->ipmi_session );
|
|
|
- cchar *pStr;
|
|
|
- int code = 200;
|
|
|
- cJSON * root = cJSON_CreateObject();
|
|
|
- cJSON * data = cJSON_CreateObject();
|
|
|
- // cJSON * next = cJSON_CreateObject();
|
|
|
- cJSON_AddItemToObject(root, "data", data);//根节点下添加
|
|
|
- cJSON_AddItemToObject(root, "msg", cJSON_CreateString(""));
|
|
|
- cJSON_AddItemToObject(root, "code", cJSON_CreateString("200"));
|
|
|
- cJSON_AddStringToObject(data, "BuildTime", BuildTime);
|
|
|
- cJSON_AddStringToObject(data, "FwVersion", FwVersion);
|
|
|
-
|
|
|
- pStr = cJSON_Print(root);
|
|
|
-
|
|
|
- printf("first json:\n%s\n", pStr);
|
|
|
- logmsg(2, "-----------------------jso1n----------------------%s", pStr);
|
|
|
+ // logmsg(2, "--------------------ggggggggg----------------");
|
|
|
+
|
|
|
+ // uint16_t wRet = LIBIPMI_E_SUCCESS;
|
|
|
+ // GetDevIDRes_T DeviceID;
|
|
|
+ char BuildTime[30] = "2020-3-10";
|
|
|
+ char FwVersion[10] = "1.0";
|
|
|
+ // //Create session
|
|
|
+ // LIBIPMI_CreateSession(&wp->ipmi_session, 10);
|
|
|
+ // sprintf(BuildTime, "%s %s", __DATE__, __TIME__);
|
|
|
+ // wRet = IPMICMD_GetDeviceID( &wp->ipmi_session, &DeviceID, DEFAULT_TIMEOUT);
|
|
|
+ // if (wRet == LIBIPMI_E_SUCCESS)
|
|
|
+ // {
|
|
|
+ // sprintf(FwVersion, "%d.%d", DeviceID.FirmwareRevision1, DeviceID.FirmwareRevision2);
|
|
|
+ // }
|
|
|
+ // printf("BuildTime: %s\n", BuildTime);
|
|
|
+ // printf("FwVersion: %s\n", FwVersion);
|
|
|
+ // //Close session
|
|
|
+ // LIBIPMI_CloseSession(&wp->ipmi_session );
|
|
|
+ // cchar *pStr;
|
|
|
+ // int code = 200;
|
|
|
+ // cJSON * root = cJSON_CreateObject();
|
|
|
+ // cJSON * data = cJSON_CreateObject();
|
|
|
+ // // cJSON * next = cJSON_CreateObject();
|
|
|
+ // cJSON_AddItemToObject(root, "data", data);//根节点下添加
|
|
|
+ // cJSON_AddItemToObject(root, "msg", cJSON_CreateString(""));
|
|
|
+ // cJSON_AddItemToObject(root, "code", cJSON_CreateString("200"));
|
|
|
+ // cJSON_AddStringToObject(data, "BuildTime", BuildTime);
|
|
|
+ // cJSON_AddStringToObject(data, "FwVersion", FwVersion);
|
|
|
+
|
|
|
+ // pStr = cJSON_Print(root);
|
|
|
+
|
|
|
+ //printf("first json:\n%s\n", pStr);
|
|
|
|
|
|
websSetStatus(wp, 200);
|
|
|
websWriteHeaders(wp, -1, 0);
|