bump for release
[uclibc-ng.git] / test / inet / gethost_r-align.c
blob53ce93acd379e1a59124bb88341cadef1f042af2
1 /* Since the reentrant gethost functions take a char * buffer,
2 * we have to make sure they internally do not assume alignment.
3 * The actual return values are not relevant. If the test fails,
4 * it'll be due to an alignment exception which means the test
5 * app is killed by the kernel.
6 */
8 #include <errno.h>
9 #include <netdb.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <arpa/inet.h>
14 #include <sys/socket.h>
16 int main(int argc, char *argv[])
18 size_t i;
19 char buf[1024];
20 in_addr_t addr;
22 addr = inet_addr("127.0.0.1");
24 for (i = 0; i < sizeof(size_t) * 2; ++i) {
25 struct hostent hent, *hentres;
26 int ret, herr;
28 printf("Testing misalignment of %2zi bytes: ", i);
30 memset(&hent, 0x00, sizeof(hent));
31 ret = gethostent_r(&hent, buf + i, sizeof(buf) - i, &hentres, &herr);
32 printf("%sgethostent_r() ", (ret ? "!!!" : ""));
34 memset(&hent, 0x00, sizeof(hent));
35 ret = gethostbyname_r("localhost", &hent, buf + i, sizeof(buf) - i, &hentres, &herr);
36 printf("%sgethostbyname_r() ", (ret ? "!!!" : ""));
38 memset(&hent, 0x00, sizeof(hent));
39 ret = gethostbyname2_r("localhost", AF_INET, &hent, buf + i, sizeof(buf) - i, &hentres, &herr);
40 printf("%sgethostbyname2_r() ", (ret ? "!!!" : ""));
42 memset(&hent, 0x00, sizeof(hent));
43 ret = gethostbyaddr_r(&addr, sizeof(addr), AF_INET, &hent, buf + i, sizeof(buf) - i, &hentres, &herr);
44 printf("%sgethostbyaddr_r() ", (ret ? "!!!" : ""));
46 puts("OK!");
49 return 0;