blob: 53ce93acd379e1a59124bb88341cadef1f042af2 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* 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 */
7
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>
15
16int main(int argc, char *argv[])
17{
18 size_t i;
19 char buf[1024];
20 in_addr_t addr;
21
22 addr = inet_addr("127.0.0.1");
23
24 for (i = 0; i < sizeof(size_t) * 2; ++i) {
25 struct hostent hent, *hentres;
26 int ret, herr;
27
28 printf("Testing misalignment of %2zi bytes: ", i);
29
30 memset(&hent, 0x00, sizeof(hent));
31 ret = gethostent_r(&hent, buf + i, sizeof(buf) - i, &hentres, &herr);
32 printf("%sgethostent_r() ", (ret ? "!!!" : ""));
33
34 memset(&hent, 0x00, sizeof(hent));
35 ret = gethostbyname_r("localhost", &hent, buf + i, sizeof(buf) - i, &hentres, &herr);
36 printf("%sgethostbyname_r() ", (ret ? "!!!" : ""));
37
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 ? "!!!" : ""));
41
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 ? "!!!" : ""));
45
46 puts("OK!");
47 }
48
49 return 0;
50}