回答編集履歴
2
inet_ntop2をinet_ntopにかえました。
test
CHANGED
@@ -54,7 +54,7 @@
|
|
54
54
|
|
55
55
|
|
56
56
|
|
57
|
-
if (inet_ntop
|
57
|
+
if (inet_ntop(&a, dst, sizeof dst)) {
|
58
58
|
|
59
59
|
printf("%s\n", dst);
|
60
60
|
|
1
mainのみかいてみました。
test
CHANGED
@@ -7,3 +7,71 @@
|
|
7
7
|
130.00.7.23
|
8
8
|
|
9
9
|
888.999.333.000
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
```C
|
14
|
+
|
15
|
+
int main()
|
16
|
+
|
17
|
+
{
|
18
|
+
|
19
|
+
struct in_addr a;
|
20
|
+
|
21
|
+
char dst[256];
|
22
|
+
|
23
|
+
FILE *fp;
|
24
|
+
|
25
|
+
char buff[256];
|
26
|
+
|
27
|
+
int len;
|
28
|
+
|
29
|
+
in_addr_t ret;
|
30
|
+
|
31
|
+
fp = fopen("test.txt","r");
|
32
|
+
|
33
|
+
if (fp == NULL){
|
34
|
+
|
35
|
+
printf("file open error\n");
|
36
|
+
|
37
|
+
return(10);
|
38
|
+
|
39
|
+
}
|
40
|
+
|
41
|
+
while(1){
|
42
|
+
|
43
|
+
memset(buff,0x00,sizeof(buff));
|
44
|
+
|
45
|
+
if (fgets(buff,sizeof(buff)-1,fp) == NULL) break;
|
46
|
+
|
47
|
+
len = strlen(buff);
|
48
|
+
|
49
|
+
buff[len-1] = '\0'; //改行の削除
|
50
|
+
|
51
|
+
printf("data=<%s>\n",buff);
|
52
|
+
|
53
|
+
a.s_addr = inet_addr(buff);
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
if (inet_ntop2(&a, dst, sizeof dst)) {
|
58
|
+
|
59
|
+
printf("%s\n", dst);
|
60
|
+
|
61
|
+
} else {
|
62
|
+
|
63
|
+
printf("inet_ntop error\n");
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
fclose(fp);
|
70
|
+
|
71
|
+
return(0);
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
```
|