diff options
Diffstat (limited to 'usr/klibc/inet/inet_aton.c')
-rw-r--r-- | usr/klibc/inet/inet_aton.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/usr/klibc/inet/inet_aton.c b/usr/klibc/inet/inet_aton.c new file mode 100644 index 0000000..beceeea --- /dev/null +++ b/usr/klibc/inet/inet_aton.c @@ -0,0 +1,22 @@ +/* + * inet/inet_aton.c + */ + +#include <arpa/inet.h> +#include <stdio.h> + +int inet_aton(const char *str, struct in_addr *addr) +{ + union { + uint8_t b[4]; + uint32_t l; + } a; + + if (sscanf(str, "%hhu.%hhu.%hhu.%hhu", + &a.b[0], &a.b[1], &a.b[2], &a.b[3]) == 4) { + addr->s_addr = a.l; /* Always in network byte order */ + return 1; + } else { + return 0; + } +} |