1 // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s 2 3 #include <netdb.h> 4 #include <stdio.h> 5 #include <stdlib.h> 6 7 #define STRING_OR_NULL(x) ((x) ? (x) : "null") 8 9 void test1() { 10 struct protoent *ptp = getprotoent(); 11 12 printf("%s ", STRING_OR_NULL(ptp->p_name)); 13 14 for (char **cp = ptp->p_aliases; *cp != NULL; cp++) 15 printf("%s ", STRING_OR_NULL(*cp)); 16 17 printf("%d\n", ptp->p_proto); 18 endprotoent(); 19 } 20 21 void test2() { 22 struct protoent *ptp = getprotobyname("icmp"); 23 24 printf("%s ", STRING_OR_NULL(ptp->p_name)); 25 26 for (char **cp = ptp->p_aliases; *cp != NULL; cp++) 27 printf("%s ", STRING_OR_NULL(*cp)); 28 29 printf("%d\n", ptp->p_proto); 30 endprotoent(); 31 } 32 33 void test3() { 34 struct protoent *ptp = getprotobynumber(1); 35 36 printf("%s ", STRING_OR_NULL(ptp->p_name)); 37 38 for (char **cp = ptp->p_aliases; *cp != NULL; cp++) 39 printf("%s ", STRING_OR_NULL(*cp)); 40 41 printf("%d\n", ptp->p_proto); 42 endprotoent(); 43 } 44 45 void test4() { 46 setprotoent(1); 47 struct protoent *ptp = getprotobynumber(1); 48 49 ptp = getprotobynumber(2); 50 51 printf("%s ", STRING_OR_NULL(ptp->p_name)); 52 53 for (char **cp = ptp->p_aliases; *cp != NULL; cp++) 54 printf("%s ", STRING_OR_NULL(*cp)); 55 56 printf("%d\n", ptp->p_proto); 57 endprotoent(); 58 } 59 60 void test5() { 61 struct protoent *ptp = getprotobyname("ttp"); 62 63 printf("%s ", STRING_OR_NULL(ptp->p_name)); 64 65 for (char **cp = ptp->p_aliases; *cp != NULL; cp++) 66 printf("%s ", STRING_OR_NULL(*cp)); 67 68 printf("%d\n", ptp->p_proto); 69 endprotoent(); 70 } 71 72 int main(void) { 73 printf("protoent\n"); 74 75 test1(); 76 test2(); 77 test3(); 78 test4(); 79 test5(); 80 81 // CHECK: protoent 82 // CHECK: hopopt HOPOPT 0 83 // CHECK: icmp ICMP 1 84 // CHECK: icmp ICMP 1 85 // CHECK: igmp IGMP 2 86 // CHECK: ttp TTP iptm IPTM 84 87 88 return 0; 89 } 90