Subject: RE: API suggestion

From: Richard Draves <[email-masked]>
Date: Tue, 21 Dec 1999 10:28:05 -0800

> 	At least for 4.4BSD derived systems, "port" portion is located
> 	at same bits for sockaddr_in6 and sockaddr_in.
> 	I do not get why you need sockaddr_ip.  struct addrinfo 
> is tagged
> 	correctly with ai_family so there should be no trouble.

I was using sockaddr_storage variables that were holding either AF_INET or
AF_INET6 addresses and I wanted to fetch/store the port field. So my choices
were
a) look at the family and cast to the right structure -> unnecessary code
b) just cast to sockaddr_in without looking at family -> unpleasant
assumptions

I would have been happier using sockaddr_ip variables where I could directly
access the port field without casting.

Rich
--------------------------------------------------------------------
IETF IPng Working Group Mailing List
IPng Home Page:                      http://playground.sun.com/ipng
FTP archive:                      ftp://playground.sun.com/pub/ipng
Direct all administrative requests to [email-masked]
--------------------------------------------------------------------

---

From: [email-masked]
Date: Wed, 22 Dec 1999 10:05:38 +0900

>b) just cast to sockaddr_in without looking at family -> unpleasant

	first of all you sholud not assume AF_INET or AF_INET6 in the above....
	you should check family every time you make use of the sockaddr_storage.

	You can always define a union like:

	union sockaddr_union {
		struct sockaddr sa;
		struct sockaddr_in sin;
		struct sockaddr_in6 sin6;
	};

	or, if port field is known to be on the same offset on your system:

	union sockaddr_union {
		struct {
			u_int8_t _len;
			u_int8_t _family;
			u_int16_t _port;
		} _su;
#define su_port _su._port
		struct sockaddr sa;
		struct sockaddr_in sin;
		struct sockaddr_in6 sin6;
	};

	to avoid casting.

>access the port field without casting.

	which API should return this structure, or which structure will convert
	normal sockaddr_{in,in6} to sockaddr_ip?

itojun