blob: f522d717c54eca28cfef6fc81a6ec950db836f03 (
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
|
#include <netdb.h>
#include <arpa/inet.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
int main() {
struct servent *ret = getservbyport(htons(80), "tcp");
assert(ret);
assert(!strcmp("http", ret->s_name));
assert(ret->s_port == htons(80));
assert(!strcmp("tcp", ret->s_proto));
ret = getservbyport(htons(80), NULL);
assert(ret);
assert(!strcmp("http", ret->s_name));
assert(ret->s_port == htons(80));
assert(!strcmp("tcp", ret->s_proto));
ret = getservbyport(htons(6696), "udp");
assert(ret);
ret = getservbyport(htons(6696), "tcp");
assert(!ret);
ret = getservbyport(htons(0), NULL);
assert(!ret);
return 0;
}
|