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.
13 #include <arpa/inet.h>
14 #include <sys/socket.h>
16 int main(int argc
, char *argv
[])
22 addr
= inet_addr("127.0.0.1");
24 for (i
= 0; i
< sizeof(size_t) * 2; ++i
) {
25 struct hostent hent
, *hentres
;
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
? "!!!" : ""));