-
#include <stdio.h>
-
#include <string.h>
-
#include <arpa/inet.h>
-
-
uint32_t ip2uint(const char *ip) {
-
int a, b, c, d;
-
uint32_t addr = 0;
-
-
if (sscanf(ip, "%d.%d.%d.%d", &a, &b, &c, &d) != 4)
-
return 0;
-
-
addr = a << 24;
-
addr |= b << 16;
-
addr |= c << 8;
-
addr |= d;
-
return addr;
-
}
-
-
int main()
-
{
-
printf("%u\n", ip2uint("0.0.0.0"));
-
printf("%u\n", ip2uint("1.0.0.1"));
-
printf("%u\n", ip2uint("222.202.55.66"));
-
printf("%u\n", ip2uint("255.255.255.255"));
-
-
FILE *fp1;
-
char c;
-
fp1= fopen ("ctrl.txt", "r");
-
c = fgetc(fp1);
-
printf("%c\n", c);
-
fclose(fp1);
-
}
[root@localhost 桌面]# gcc tmp.c -o tmp
[root@localhost 桌面]# ./tmp
0
16777217
3737794370
4294967295
[root@localhost 桌面]#
阅读(1121) | 评论(0) | 转发(0) |