| 1 |
// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s |
| 2 |
|
| 3 |
#include <inttypes.h> |
| 4 |
#include <netdb.h> |
| 5 |
#include <stdint.h> |
| 6 |
#include <stdio.h> |
| 7 |
#include <stdlib.h> |
| 8 |
|
| 9 |
#define STRING_OR_NULL(x) ((x) ? (x) : "null") |
| 10 |
|
| 11 |
void test1() { |
| 12 |
struct netent *ntp = getnetent(); |
| 13 |
|
| 14 |
printf("%s ", ntp->n_name); |
| 15 |
|
| 16 |
for (char **cp = ntp->n_aliases; *cp != NULL; cp++) |
| 17 |
printf("%s ", STRING_OR_NULL(*cp)); |
| 18 |
|
| 19 |
printf("%d ", ntp->n_addrtype); |
| 20 |
printf("%" PRIu32 "\n", ntp->n_net); |
| 21 |
|
| 22 |
endnetent(); |
| 23 |
} |
| 24 |
|
| 25 |
void test2() { |
| 26 |
struct netent *ntp = getnetbyname("loopback"); |
| 27 |
|
| 28 |
printf("%s ", ntp->n_name); |
| 29 |
|
| 30 |
for (char **cp = ntp->n_aliases; *cp != NULL; cp++) |
| 31 |
printf("%s ", STRING_OR_NULL(*cp)); |
| 32 |
|
| 33 |
printf("%d ", ntp->n_addrtype); |
| 34 |
printf("%" PRIu32 "\n", ntp->n_net); |
| 35 |
|
| 36 |
endnetent(); |
| 37 |
} |
| 38 |
|
| 39 |
void test3() { |
| 40 |
struct netent *ntp = getnetbyaddr(127, 2); |
| 41 |
|
| 42 |
printf("%s ", ntp->n_name); |
| 43 |
|
| 44 |
for (char **cp = ntp->n_aliases; *cp != NULL; cp++) |
| 45 |
printf("%s ", STRING_OR_NULL(*cp)); |
| 46 |
|
| 47 |
printf("%d ", ntp->n_addrtype); |
| 48 |
printf("%" PRIu32 "\n", ntp->n_net); |
| 49 |
|
| 50 |
endnetent(); |
| 51 |
} |
| 52 |
|
| 53 |
void test4() { |
| 54 |
setnetent(1); |
| 55 |
|
| 56 |
struct netent *ntp = getnetent(); |
| 57 |
|
| 58 |
printf("%s ", ntp->n_name); |
| 59 |
|
| 60 |
for (char **cp = ntp->n_aliases; *cp != NULL; cp++) |
| 61 |
printf("%s ", STRING_OR_NULL(*cp)); |
| 62 |
|
| 63 |
printf("%d ", ntp->n_addrtype); |
| 64 |
printf("%" PRIu32 "\n", ntp->n_net); |
| 65 |
|
| 66 |
endnetent(); |
| 67 |
} |
| 68 |
|
| 69 |
int main(void) { |
| 70 |
printf("netent\n"); |
| 71 |
|
| 72 |
test1(); |
| 73 |
test2(); |
| 74 |
test3(); |
| 75 |
test4(); |
| 76 |
|
| 77 |
// CHECK: netent |
| 78 |
// CHECK: loopback 2 127 |
| 79 |
// CHECK: loopback 2 127 |
| 80 |
// CHECK: loopback 2 127 |
| 81 |
// CHECK: loopback 2 127 |
| 82 |
|
| 83 |
return 0; |
| 84 |
} |