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
11void test1() {
12 struct netent *ntp = getnetent();
13
14 printf(format: "%s ", ntp->n_name);
15
16 for (char **cp = ntp->n_aliases; *cp != NULL; cp++)
17 printf(format: "%s ", STRING_OR_NULL(*cp));
18
19 printf(format: "%d ", ntp->n_addrtype);
20 printf(format: "%" PRIu32 "\n", ntp->n_net);
21
22 endnetent();
23}
24
25void test2() {
26 struct netent *ntp = getnetbyname(name: "loopback");
27
28 printf(format: "%s ", ntp->n_name);
29
30 for (char **cp = ntp->n_aliases; *cp != NULL; cp++)
31 printf(format: "%s ", STRING_OR_NULL(*cp));
32
33 printf(format: "%d ", ntp->n_addrtype);
34 printf(format: "%" PRIu32 "\n", ntp->n_net);
35
36 endnetent();
37}
38
39void test3() {
40 struct netent *ntp = getnetbyaddr(net: 127, type: 2);
41
42 printf(format: "%s ", ntp->n_name);
43
44 for (char **cp = ntp->n_aliases; *cp != NULL; cp++)
45 printf(format: "%s ", STRING_OR_NULL(*cp));
46
47 printf(format: "%d ", ntp->n_addrtype);
48 printf(format: "%" PRIu32 "\n", ntp->n_net);
49
50 endnetent();
51}
52
53void test4() {
54 setnetent(1);
55
56 struct netent *ntp = getnetent();
57
58 printf(format: "%s ", ntp->n_name);
59
60 for (char **cp = ntp->n_aliases; *cp != NULL; cp++)
61 printf(format: "%s ", STRING_OR_NULL(*cp));
62
63 printf(format: "%d ", ntp->n_addrtype);
64 printf(format: "%" PRIu32 "\n", ntp->n_net);
65
66 endnetent();
67}
68
69int main(void) {
70 printf(format: "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}
85

source code of compiler-rt/test/sanitizer_common/TestCases/NetBSD/netent.cpp