summaryrefslogtreecommitdiff
path: root/src/net/ipv4.c
blob: b30fe1531e99c8109f7e53c5a8c94cf58fb20fff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "ipv4.h"

#include "stdio.h"
#include "string.h"

char *network_ipv4_address_to_string( network_ipv4_address_t addr, char *buf, size_t buflen )
{
	snprintf( buf, buflen, "%d.%d.%d.%d",
		addr.byte[0], addr.byte[1],
		addr.byte[2], addr.byte[3] );

	return buf;
}

char *network_ipv4_protocol_to_string( network_ipv4_protocol_t protocol, char *buf, size_t buflen )
{
	switch( protocol ) {
		case NETWORK_IPV4_PROTOCOL_ICMP:
			strlcpy( buf, "ICMP", NETWORK_PROTOCOL_IPV4_PROTOCOL_STRING );
			break;
		
		case NETWORK_IPV4_PROTOCOL_UDP:
			strlcpy( buf, "UDP", NETWORK_PROTOCOL_IPV4_PROTOCOL_STRING );
			break;

		default:
			strlcpy( buf, "?", NETWORK_PROTOCOL_IPV4_PROTOCOL_STRING );
			break;
	}
	return buf;
}