| 1 |
// RUN: %clangxx -O0 -g %s -o %t |
| 2 |
// |
| 3 |
|
| 4 |
// bionic/netdb.cpp is not implemented. |
| 5 |
// UNSUPPORTED: android |
| 6 |
|
| 7 |
#include <netdb.h> |
| 8 |
#include <stdio.h> |
| 9 |
#include <stdlib.h> |
| 10 |
#include <assert.h> |
| 11 |
|
| 12 |
void test1() { |
| 13 |
struct protoent *ptp = getprotoent(); |
| 14 |
assert(ptp && ptp->p_name); |
| 15 |
assert(ptp->p_proto == 0); |
| 16 |
char **aliases = ptp->p_aliases; |
| 17 |
while (aliases) { |
| 18 |
printf("%s\n", *aliases); |
| 19 |
aliases++; |
| 20 |
} |
| 21 |
endprotoent(); |
| 22 |
} |
| 23 |
|
| 24 |
void test2() { |
| 25 |
struct protoent *ptp = getprotobyname("tcp"); |
| 26 |
assert(ptp && ptp->p_name); |
| 27 |
assert(ptp->p_proto == 6); |
| 28 |
char **aliases = ptp->p_aliases; |
| 29 |
while (aliases) { |
| 30 |
printf("%s\n", *aliases); |
| 31 |
aliases++; |
| 32 |
} |
| 33 |
endprotoent(); |
| 34 |
} |
| 35 |
|
| 36 |
void test3() { |
| 37 |
struct protoent *ptp = getprotobynumber(1); |
| 38 |
assert(ptp && ptp->p_name); |
| 39 |
assert(ptp->p_proto == 1); |
| 40 |
char **aliases = ptp->p_aliases; |
| 41 |
while (aliases) { |
| 42 |
printf("%s\n", *aliases); |
| 43 |
aliases++; |
| 44 |
} |
| 45 |
endprotoent(); |
| 46 |
} |
| 47 |
|
| 48 |
void test4() { |
| 49 |
setprotoent(1); |
| 50 |
struct protoent *ptp = getprotobynumber(1); |
| 51 |
|
| 52 |
ptp = getprotobynumber(2); |
| 53 |
assert(ptp && ptp->p_name); |
| 54 |
assert(ptp->p_proto == 2); |
| 55 |
endprotoent(); |
| 56 |
} |
| 57 |
|
| 58 |
int main(void) { |
| 59 |
printf("protoent\n"); |
| 60 |
|
| 61 |
test1(); |
| 62 |
test2(); |
| 63 |
test3(); |
| 64 |
test4(); |
| 65 |
|
| 66 |
return 0; |
| 67 |
} |