1 #include <features.h> 2 #include <ctype.h> 3 #include <sys/socket.h> 4 #include <netinet/in.h> 5 #include <arpa/inet.h> 6 #include <stdlib.h> 7 __inet_aton(const char * s0,struct in_addr * dest)8int __inet_aton(const char *s0, struct in_addr *dest) 9 { 10 const char *s = s0; 11 unsigned char *d = (void *)dest; 12 unsigned long a[4] = { 0 }; 13 char *z; 14 int i; 15 16 for (i=0; i<4; i++) { 17 a[i] = strtoul(s, &z, 0); 18 if (z==s || (*z && *z != '.') || !isdigit(*s)) 19 return 0; 20 if (!*z) break; 21 s=z+1; 22 } 23 if (i==4) return 0; 24 switch (i) { 25 case 0: 26 a[1] = a[0] & 0xffffff; 27 a[0] >>= 24; 28 case 1: 29 a[2] = a[1] & 0xffff; 30 a[1] >>= 16; 31 case 2: 32 a[3] = a[2] & 0xff; 33 a[2] >>= 8; 34 } 35 for (i=0; i<4; i++) { 36 if (a[i] > 255) return 0; 37 d[i] = a[i]; 38 } 39 return 1; 40 } 41 42 weak_alias(__inet_aton, inet_aton); 43