1 char temp[] = "192.168.190.160";
2 unsigned result = (((((192u<<8)|168u)<<8)|190u)<<8)|160u;
3
4 int strtoul1(const char *a, char **b, int c) __attribute__((noinline, noclone));
strtoul1(const char * a,char ** b,int c)5 int strtoul1(const char *a, char **b, int c)
6 {
7 *b = a+3;
8 if (a == temp)
9 return 192;
10 else if (a == temp+4)
11 return 168;
12 else if (a == temp+8)
13 return 190;
14 else if (a == temp+12)
15 return 160;
16 __builtin_abort();
17 }
18
19 int string_to_ip(const char *s) __attribute__((noinline,noclone));
string_to_ip(const char * s)20 int string_to_ip(const char *s)
21 {
22 int addr;
23 char *e;
24 int i;
25
26 if (s == 0)
27 return(0);
28
29 for (addr=0, i=0; i<4; ++i) {
30 int val = s ? strtoul1(s, &e, 10) : 0;
31 addr <<= 8;
32 addr |= (val & 0xFF);
33 if (s) {
34 s = (*e) ? e+1 : e;
35 }
36 }
37
38 return addr;
39 }
40
main(void)41 int main(void)
42 {
43 int t = string_to_ip (temp);
44 printf ("%x\n", t);
45 printf ("%x\n", result);
46 if (t != result)
47 __builtin_abort ();
48 printf ("WORKS.\n");
49 return 0;
50 }
51
52