[6bone] doubt about protocol independent Ping.

Jun-ichiro itojun Hagino itojun@itojun.org
Mon, 15 Dec 2003 16:58:41 +0900 (JST)


> Hi Itojun,
> 
> | 	Stevens' book (TCP/IP network programming) has very old description of
> | 	protocol independent programming, so do not refer it.  rather, please
> | 	refer the following:
> | 	http://www.kame.net/newsletter/19980604/
> | 	http://www.usenix.org/publications/library/proceedings/usenix2000/freenix/metzprotocol/
> 
> As a sidenote, can you explain what exactly is wrong or inconvenient
> with struct addrinfo ? I read the Book[tm] and have developped coding
> style to match Stevens' thoughts. I could be easily persuaded to change
> my code, but do not see any benefit of the sockaddr_storage yet. There's
> already a struct sockaddr in struct addrinfo, along with an ai_family and
> ai_addrlen .. so what bonus do I get from sockaddr_storage ?

	sockaddr_storage is useful when you need to reserve a chunk of memory 
	to be used for getpeername/getsockname.  it is ensured to be bigger
	than any type of sockaddrs, so if you write a program like

		struct sockaddr_storage ss;
		socklen_t slen;

		slen = sizeof(ss);
		error = getpeername(s, (struct sockaddr *)&ss, &slen);

	it will work on any platform, regardless from what kind of sockaddr
	the system might have.  if you write something like

		char ss[32];
		socklen_t slen;

		slen = sizeof(ss);
		error = getpeername(s, (struct sockaddr *)&ss, &slen);

	you will experience buffer overflow if the system supports sockaddr
	bigger than 32 bytes.

itojun