OLD | NEW |
1 #include <sys/socket.h> | 1 #include <sys/socket.h> |
2 #include <netinet/in.h> | 2 #include <netinet/in.h> |
3 #include <arpa/inet.h> | 3 #include <arpa/inet.h> |
4 | 4 |
5 in_addr_t inet_network(const char *p) | 5 in_addr_t inet_network(const char* p) { |
6 { | 6 return ntohl(inet_addr(p)); |
7 » return ntohl(inet_addr(p)); | |
8 } | 7 } |
9 | 8 |
10 struct in_addr inet_makeaddr(in_addr_t n, in_addr_t h) | 9 struct in_addr inet_makeaddr(in_addr_t n, in_addr_t h) { |
11 { | 10 if (n < 256) |
12 » if (n < 256) h |= n<<24; | 11 h |= n << 24; |
13 » else if (n < 65536) h |= n<<16; | 12 else if (n < 65536) |
14 » else h |= n<<8; | 13 h |= n << 16; |
15 » return (struct in_addr){ h }; | 14 else |
| 15 h |= n << 8; |
| 16 return (struct in_addr){h}; |
16 } | 17 } |
17 | 18 |
18 in_addr_t inet_lnaof(struct in_addr in) | 19 in_addr_t inet_lnaof(struct in_addr in) { |
19 { | 20 uint32_t h = in.s_addr; |
20 » uint32_t h = in.s_addr; | 21 if (h >> 24 < 128) |
21 » if (h>>24 < 128) return h & 0xffffff; | 22 return h & 0xffffff; |
22 » if (h>>24 < 192) return h & 0xffff; | 23 if (h >> 24 < 192) |
23 » return h & 0xff; | 24 return h & 0xffff; |
| 25 return h & 0xff; |
24 } | 26 } |
25 | 27 |
26 in_addr_t inet_netof(struct in_addr in) | 28 in_addr_t inet_netof(struct in_addr in) { |
27 { | 29 uint32_t h = in.s_addr; |
28 » uint32_t h = in.s_addr; | 30 if (h >> 24 < 128) |
29 » if (h>>24 < 128) return h >> 24; | 31 return h >> 24; |
30 » if (h>>24 < 192) return h >> 16; | 32 if (h >> 24 < 192) |
31 » return h >> 8; | 33 return h >> 16; |
| 34 return h >> 8; |
32 } | 35 } |
OLD | NEW |