-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetMasterCMCip.c
More file actions
117 lines (106 loc) · 2.33 KB
/
getMasterCMCip.c
File metadata and controls
117 lines (106 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef char int8;
typedef int int32;
typedef unsigned char uint8;
typedef unsigned long long uint64;
/***********************************************************************
*******length: length to get
*******actlen: length actual got
************************************************************************/
int getHexFromFile (FILE *fp, int8 length, uint8 * buffer, uint8 *actlen) {
int i = 0, isNumber = 0;
char *databuffer = buffer, tmpchar;
while((EOF != (tmpchar = fgetc(fp))) && (i < length))
{
if(tmpchar >= 'a' && tmpchar <= 'f')
{
tmpchar = tmpchar - 'a' + 'A';
}
if((tmpchar >= 'A' && tmpchar <= 'F') || (tmpchar >= '0' && tmpchar <= '9'))
{
isNumber = 1;
if(tmpchar >= 'A' && tmpchar <= 'F')
{
databuffer[i] = databuffer[i]*16 + tmpchar - 'A' + 10;
}
else
{
databuffer[i] = databuffer[i]*16 + tmpchar - '0';
}
}
else
{
if(isNumber == 1)
{
i ++;
}
isNumber = 0;
}
}
/*i record the count of numbers have got,
if got EOF and last charactor is number, the last number has not been recorded*/
if ( (1 == isNumber) && (EOF == tmpchar) )
{
i ++;
}
*actlen = i ;
if (*actlen < length)
{
return 0;
}
else
{
return 1;
}
}
void main ()
{
int8 tmpStr[10][256] = {0},tmpchar,readlen = 8;
uint8 databuffer[256] = {0x99},tmpbuffer[256]={0};
int8 *tmpPtr[3] = {NULL};
uint8 i = 0,j = 0;
uint8 isNumber = 0;
int offset_h = 0x2b,offset_l = 0x00;
uint64 wwnn = 0;
int8 tmpcmd[] = "cat ReadorWriteResult_cpy";
FILE *fp ;
fp = popen(tmpcmd,"r");
if (fp != NULL)
{
if (1 == getHexFromFile (fp, readlen, databuffer, &i))
{
if(readlen != i )
{
printf("can't get enough data,need(%d),got(%d)\n", readlen, i);
}
}
else
{
printf("get data from fstream fail\n");
}
}
else
{
printf("popen fail\n");
}
//*/
printf("databuffer is:\n");
for(i = 0; i < readlen; i++)
{
printf("0x%02x ",databuffer[i]);
if(i % 16 == 15)
printf("\n");
}
for(i = 0; i < readlen; i++)
{
snprintf((char *)(tmpbuffer+strlen(tmpbuffer)),4+1,"%03d.",databuffer[i]);
}
tmpbuffer[strlen(tmpbuffer) - 1] = '\0';
///*code for test
printf("\ntmpbuffer is:IP\n%s\n",tmpbuffer);
//*/
strncpy(databuffer,tmpbuffer,strlen(tmpbuffer)+1);
printf("databuffer is :\n%s\n",databuffer);
}