Subject: Re: sparc hp->h_addr_list alignment problems
To: David Brownlee <abs@anim.dreamworks.com>
From: Matthias Scheler <tron@lyssa.owl.de>
List: tech-net
Date: 07/19/1999 18:30:40
On Mon, Jul 19, 1999 at 12:00:55AM -0700, David Brownlee wrote:
> Its not ELF related. After the IPv6 integration it appears that
> hp->h_addr_list is no longer suitably aligned for 32bit

From "/usr/include/netdb.h":

struct  hostent {
[...]
        char    **h_addr_list;  /* list of addresses from name server */
[...]
};

I'm pretty sure that it is aligned on a byte address. If you assume
any futher alignment of a "char *" pointer your code is incorrect.
Here is a correct piece of code taken from "src/usr.bin/ftp/fetch.c":

	hp = gethostbyname(host);
	if (hp == NULL) {
		warnx("%s: %s", host, hstrerror(h_errno));
		goto cleanup_fetch_url;
	}
	if (hp->h_addrtype != AF_INET) {
		warnx("`%s': not an Internet address?", host);
		goto cleanup_fetch_url;
	}
	memcpy(&sin.sin_addr, hp->h_addr, hp->h_length);

This will definitely work with my changes.

	Regards

-- 
Matthias Scheler                                http://home.owl.de/~tron/