- 论坛徽章:
- 0
|
下面这个是可以正常运行的程序
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
int i = 0;
unsigned char buffer[] = "192.168.0.1";
unsigned char* drop_ip = "\\xc0\\xa8\\x0\\x1";
char *p[4];
char *buff = buffer;
while(1)
{
char* token = strtok(buff, ".");
if (token != NULL)
p[i] = token;
else
break;
printf("p[%d]: %s\n", i, p[i]);
buff = NULL;
i++;
}
int temp = 0;
i = 0;
unsigned char str[12] = "";
unsigned char result[12] = "";
while(i < 4)
{
temp = atoi(p[i]);
sprintf(str,"%s%x","\\x",temp);
printf("i:%d str:%s\n",i, str);
sprintf(result,"%s%s",result,str);
printf("i:%d result:%s\n",i, result);
i++;
}
printf("result == drop_ip ? %s\n", strcmp(result, drop_ip) == 0 ? "yes" : "no");
printf("result:%d\n",*(unsigned int*)result);
printf("drop_ip:%d\n",*(unsigned int*)drop_ip);
return 0;
}
|
|
|