1// RUN: %clangxx -O0 -g %s -o %t
2//
3
4// bionic/netdb.cpp is not implemented.
5// UNSUPPORTED: android
6
7#include <netdb.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <assert.h>
11
12void test1() {
13 struct protoent *ptp = getprotoent();
14 assert(ptp && ptp->p_name);
15 assert(ptp->p_proto == 0);
16 char **aliases = ptp->p_aliases;
17 while (aliases) {
18 printf(format: "%s\n", *aliases);
19 aliases++;
20 }
21 endprotoent();
22}
23
24void test2() {
25 struct protoent *ptp = getprotobyname(name: "tcp");
26 assert(ptp && ptp->p_name);
27 assert(ptp->p_proto == 6);
28 char **aliases = ptp->p_aliases;
29 while (aliases) {
30 printf(format: "%s\n", *aliases);
31 aliases++;
32 }
33 endprotoent();
34}
35
36void test3() {
37 struct protoent *ptp = getprotobynumber(proto: 1);
38 assert(ptp && ptp->p_name);
39 assert(ptp->p_proto == 1);
40 char **aliases = ptp->p_aliases;
41 while (aliases) {
42 printf(format: "%s\n", *aliases);
43 aliases++;
44 }
45 endprotoent();
46}
47
48void test4() {
49 setprotoent(1);
50 struct protoent *ptp = getprotobynumber(proto: 1);
51
52 ptp = getprotobynumber(proto: 2);
53 assert(ptp && ptp->p_name);
54 assert(ptp->p_proto == 2);
55 endprotoent();
56}
57
58int main(void) {
59 printf(format: "protoent\n");
60
61 test1();
62 test2();
63 test3();
64 test4();
65
66 return 0;
67}
68

source code of compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp