Re: API draft: section 8.3 and 8.5

From: Kacheong Poon <kacheong.poon@sun.com>
Date: Tue Feb 08 2005 - 16:05:01 EST
('binary' encoding is not supported, stored as-is) ('binary' encoding is not supported, stored as-is) David Lehmann wrote:

> OK then, explain to me what the "mixed" return data is.
> Are you stating that there could be sockaddr_in6 elements _and_
> sockaddr_in elements returned? i.e. I can't index into the
> "array" buy rather have to move the pointer down the appropriate
> number of bytes depending on the record?

The type cast of addrs to (struct sockaddr_in *) and (struct
sockaddr_in6 *) in the following code may have problem
because of alignment issue. So it is safer to copy from
addrs to a local sockaddr variable and use the local instead.

> e.g.
> struct sockaddr *addrs;
> int count;
>
> count = sctp_getpaddrs(sd, id, &addrs);
>
> while (count-- >= 0)
> {
> if (addrs->sa_family == AF_INET)
> {
> struct sockaddr_in *sin = (struct sockaddr_in *)addrs;
>
> /* Do something with returned address */
> ...
>
> /* go to next addr */
> addrs = (struct sockaddr *)(sin + 1)
> }
> else if (addrs->sa_family == AF_INET6)
> {
> struct sockaddr_in6 *sin6 =
> (struct sockaddr_in6 *)addrs;
>
> /* Do something with returned address */
> ...
>
> /* go to next addr */
> addrs = (struct sockaddr *)(sin6 + 1)
> }
> else
> {
> /* bogus family */
> }
> }
>

-- 
						K. Poon.
						kacheong.poon@sun.com
Received on Tue Feb 8 16:07:33 2005

This archive was generated by hypermail 2.1.8 : Mon Mar 13 2006 - 15:22:23 EST