1 typedef struct { 2 int ifin, ifout; 3 unsigned int daddr, saddr; 4 } BNode; 5 parse_ip(char * p)6static unsigned int parse_ip(char *p) { 7 int k, i=0, b; 8 unsigned int ip=0; 9 for (k=0; k<4; k++) { 10 b=0; 11 if (p[i]<'0'||p[i]>'9') return 0; 12 while(p[i]>='0'&&p[i]<='9') { 13 b=b*10+p[i++]-'0'; 14 if (b>256) return 0; 15 } 16 if (k<3&&p[i]!='.') return 0; 17 if (k==3&&p[i]!=0) return 0; 18 ip = ip | (b<<(k*8)); 19 i++; 20 } 21 return ip; 22 } 23