diff --git a/include/arpa/inet.h b/include/arpa/inet.h index fdc501aa0fb8ada87d0bc80b7adf056bcf3724ea..e47a41f6fa03886b4c103ae8ca50809097d571cc 100644 --- a/include/arpa/inet.h +++ b/include/arpa/inet.h @@ -29,7 +29,10 @@ char *inet_ntoa (struct in_addr); int inet_pton (int, const char *__restrict, void *__restrict); const char *inet_ntop (int, const void *__restrict, char *__restrict, socklen_t); -int inet_aton (const char *, struct in_addr *); /* nonstandard but widely used */ +int inet_aton (const char *, struct in_addr *); +struct in_addr inet_makeaddr(int, int); +in_addr_t inet_lnaof(struct in_addr); +in_addr_t inet_netof(struct in_addr); #undef INET_ADDRSTRLEN #undef INET6_ADDRSTRLEN diff --git a/src/network/inet_addr.c b/src/network/inet_addr.c deleted file mode 100644 index 84137281ce33f2b3e6e0e8f139d9a8e0f3185ee0..0000000000000000000000000000000000000000 --- a/src/network/inet_addr.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include -#include "__dns.h" - -in_addr_t inet_addr(const char *p) -{ - struct sockaddr_in sin; - if (__ipparse(&sin, AF_INET, p)) return -1; - return sin.sin_addr.s_addr; -} diff --git a/src/network/inet_aton.c b/src/network/inet_aton.c deleted file mode 100644 index ea4ee1650ab4e72d92c8cd16c1043c02db36af7c..0000000000000000000000000000000000000000 --- a/src/network/inet_aton.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -int inet_aton(const char *cp, struct in_addr *inp) -{ - return inet_pton(AF_INET, cp, (void *)inp) > 0; -} diff --git a/src/network/inet_legacy.c b/src/network/inet_legacy.c new file mode 100644 index 0000000000000000000000000000000000000000..e802557b61b89736f213477306c9653bb906e766 --- /dev/null +++ b/src/network/inet_legacy.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include "__dns.h" + +in_addr_t inet_addr(const char *p) +{ + struct sockaddr_in sin; + if (__ipparse(&sin, AF_INET, p)) return -1; + return sin.sin_addr.s_addr; +} + +in_addr_t inet_network(const char *p) +{ + return ntohl(inet_addr(p)); +} + +int inet_aton(const char *cp, struct in_addr *inp) +{ + return inet_pton(AF_INET, cp, (void *)inp) > 0; +} + +char *inet_ntoa(struct in_addr in) +{ + static char buf[16]; + unsigned char *a = (void *)∈ + snprintf(buf, sizeof buf, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]); + return buf; +} + +struct in_addr inet_makeaddr(int net, int host) +{ + uint32_t n = net, h = host; + if (n < 256) h |= n<<24; + else if (n < 65536) h |= n<<16; + else h |= n<<8; + return (struct in_addr){ h }; +} + +in_addr_t inet_lnaof(struct in_addr in) +{ + uint32_t h = in.s_addr; + if (h>>24 < 128) return h & 0xffffff; + if (h>>24 < 192) return h & 0xffff; + return h & 0xff; +} + +in_addr_t inet_netof(struct in_addr in) +{ + uint32_t h = in.s_addr; + if (h>>24 < 128) return h >> 24; + if (h>>24 < 192) return h >> 16; + return h >> 8; +} diff --git a/src/network/inet_network.c b/src/network/inet_network.c deleted file mode 100644 index ae60d7f658b8230bd8d23633158d3c1f3013798f..0000000000000000000000000000000000000000 --- a/src/network/inet_network.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include -#include "__dns.h" - -in_addr_t inet_network(const char *p) -{ - struct sockaddr_in sin; - if (__ipparse(&sin, AF_INET, p)) return -1; - return ntohl(sin.sin_addr.s_addr); -} diff --git a/src/network/inet_ntoa.c b/src/network/inet_ntoa.c deleted file mode 100644 index 71411e0b5f145a59838a02149ef26644e6e4199f..0000000000000000000000000000000000000000 --- a/src/network/inet_ntoa.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -char *inet_ntoa(struct in_addr in) -{ - static char buf[16]; - unsigned char *a = (void *)∈ - snprintf(buf, sizeof buf, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]); - return buf; -}