1 // RUN: %clangxx -O0 -g %s -o %t 2 // 3 // REQUIRES: linux, freebsd 4 5 #include <inttypes.h> 6 #include <netdb.h> 7 #include <stdint.h> 8 #include <stdio.h> 9 #include <stdlib.h> 10 #include <assert.h> 11 12 #if defined(__linux__) 13 #define LOOPBACK "loopback" 14 #else 15 #define LOOPBACK "your-net" 16 #endif 17 test1()18void test1() { 19 struct netent *ntp = getnetent(); 20 assert(ntp && ntp->n_name); 21 assert(ntp->n_addrtype == 2); 22 assert(ntp->n_net == 127); 23 endnetent(); 24 } 25 test2()26void test2() { 27 struct netent *ntp = getnetbyname(LOOPBACK); 28 assert(ntp && ntp->n_name); 29 assert(ntp->n_addrtype == 2); 30 assert(ntp->n_net == 127); 31 endnetent(); 32 } 33 test3()34void test3() { 35 struct netent *lb = getnetbyname(LOOPBACK); 36 assert(lb); 37 struct netent *ntp = getnetbyaddr(lb->n_net, lb->n_addrtype); 38 assert(ntp && ntp->n_name); 39 assert(ntp->n_addrtype == 2); 40 assert(ntp->n_net == 127); 41 endnetent(); 42 } 43 test4()44void test4() { 45 setnetent(1); 46 47 struct netent *ntp = getnetent(); 48 assert(ntp && ntp->n_name); 49 assert(ntp->n_addrtype == 2); 50 assert(ntp->n_net == 127); 51 endnetent(); 52 } 53 main(void)54int main(void) { 55 printf("netent\n"); 56 57 test1(); 58 test2(); 59 test3(); 60 test4(); 61 62 return 0; 63 } 64