1 #include <sys/socket.h>
2 #include <netinet/in.h>
6 in_addr_t inet_network(const char *p)
8 return ntohl(inet_addr(p));
11 int inet_aton(const char *cp, struct in_addr *inp)
13 return inet_pton(AF_INET, cp, (void *)inp) > 0;
16 struct in_addr inet_makeaddr(int net, int host)
18 uint32_t n = net, h = host;
19 if (n < 256) h |= n<<24;
20 else if (n < 65536) h |= n<<16;
22 return (struct in_addr){ h };
25 in_addr_t inet_lnaof(struct in_addr in)
27 uint32_t h = in.s_addr;
28 if (h>>24 < 128) return h & 0xffffff;
29 if (h>>24 < 192) return h & 0xffff;
33 in_addr_t inet_netof(struct in_addr in)
35 uint32_t h = in.s_addr;
36 if (h>>24 < 128) return h >> 24;
37 if (h>>24 < 192) return h >> 16;