aboutsummaryrefslogtreecommitdiffstats
path: root/usr/klibc/inet/inet_aton.c
blob: beceeea36a733c2c264dfb157526714b8dc94be1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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;
	}
}