1 // RUN: %clangxx -O0 -g %s -o %t
2 //
3 // REQUIRES: linux, freebsd
4 
5 #include <netdb.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <assert.h>
9 
test1()10 void test1() {
11   struct protoent *ptp = getprotoent();
12   assert(ptp && ptp->p_name);
13   assert(ptp->p_proto == 0);
14   endprotoent();
15 }
16 
test2()17 void test2() {
18   struct protoent *ptp = getprotobyname("tcp");
19   assert(ptp && ptp->p_name);
20   assert(ptp->p_proto == 6);
21   endprotoent();
22 }
23 
test3()24 void test3() {
25   struct protoent *ptp = getprotobynumber(1);
26   assert(ptp && ptp->p_name);
27   assert(ptp->p_proto == 1);
28   endprotoent();
29 }
30 
test4()31 void test4() {
32   setprotoent(1);
33   struct protoent *ptp = getprotobynumber(1);
34 
35   ptp = getprotobynumber(2);
36   assert(ptp && ptp->p_name);
37   assert(ptp->p_proto == 2);
38   endprotoent();
39 }
40 
main(void)41 int main(void) {
42   printf("protoent\n");
43 
44   test1();
45   test2();
46   test3();
47   test4();
48 
49   return 0;
50 }
51