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