aboutsummaryrefslogtreecommitdiff
path: root/lib/mlibc/tests/posix/getservbyname.c
blob: 8c51710d378812ceb6c9e69936d214799ead53bf (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
#include <assert.h>
#include <netdb.h>
#include <string.h>
#include <arpa/inet.h>

int main() {
	struct servent *ret = getservbyname("http", "tcp");
	assert(ret);
	assert(!strcmp("http", ret->s_name));
	assert(ret->s_port == htons(80));
	assert(!strcmp("tcp", ret->s_proto));

	ret = getservbyname("http", NULL);
	assert(ret);
	assert(!strcmp("http", ret->s_name));
	assert(ret->s_port == htons(80));
	assert(!strcmp("tcp", ret->s_proto));

	ret = getservbyname("babel", "udp");
	assert(ret);
	ret = getservbyname("babel", "tcp");
	assert(!ret);

	ret = getservbyname("", NULL);
	assert(!ret);
	return 0;
}