| /* |
| * This file is part of the UCB release of Plan 9. It is subject to the license |
| * terms in the LICENSE file found in the top-level directory of this |
| * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No |
| * part of the UCB release of Plan 9, including this file, may be copied, |
| * modified, propagated, or distributed except according to the terms contained |
| * in the LICENSE file. |
| */ |
| /* posix */ |
| #include <sys/types.h> |
| #include <unistd.h> |
| #include <stdlib.h> |
| #include <string.h> |
| |
| /* bsd extensions */ |
| #include <sys/uio.h> |
| #include <sys/socket.h> |
| #include <netinet/in.h> |
| |
| #include "priv.h" |
| |
| /* where to define this? only used once? */ |
| unsigned long nptohl(void *p); |
| |
| #define CLASS(x) (x[0]>>6) |
| |
| unsigned long |
| inet_addr(char *from) |
| { |
| int i; |
| char *p; |
| unsigned char to[4]; |
| unsigned long x; |
| |
| p = from; |
| memset(to, 0, 4); |
| for(i = 0; i < 4 && *p; i++){ |
| to[i] = strtoul(p, &p, 0); |
| if(*p == '.') |
| p++; |
| } |
| |
| switch(CLASS(to)){ |
| case 0: /* class A - 1 byte net */ |
| case 1: |
| if(i == 3){ |
| to[3] = to[2]; |
| to[2] = to[1]; |
| to[1] = 0; |
| } else if (i == 2){ |
| to[3] = to[1]; |
| to[1] = 0; |
| } |
| break; |
| case 2: /* class B - 2 byte net */ |
| if(i == 3){ |
| to[3] = to[2]; |
| to[2] = 0; |
| } |
| break; |
| } |
| x = nptohl(to); |
| x = htonl(x); |
| return x; |
| } |