Subject: Re: Question about sctp_get[lp]addrs().

From: KOZUKA Masahiro <[email-masked]>
Date: Thu, 25 Mar 2004 15:39:37 +0900

Randall-san,
On Wed, Mar 24, 2004 at 05:59:46AM -0600, Randall Stewart (cisco) wrote:
> Yes, it is true that only BSD has the sa_len. But a couple of things:
> 
> 1) If you have an AF_INET6 socket and you specify the default
>    behavior (according to the socket draft), all addresses will
>    be mapped to V6.
> 
> 2) If you have an AF_INET socket and you do this... all you get
>    is  V4 addresses.
> 
> 3) If you do turn off the mapped addresses (yes I know kame does
>    this by default) you will get a mix of AF_INET and AF_INET6 
> addresses (yes
>    Kacheong I know you hate this :-0). But even if you did this in 
> linux land or
>    wanted portable code .. one could do
> struct sockaddr *sa;
> int not_done=0;
> not_done =  sctp_get[lp]addrs(&sa);
> while(not_done)
>    if(sa->sa_family == AF_INET)
>          len = sizeof(struct sockaddr_in)
>    else if(sa->sa_family == AF_INET6)
>          len = sizeof(struct sockaddr_in6_
>    else
>          break;
>    print-address(sa);
>    sa = ((caddr_t)sa + len);
>    not_done--;
> }
> 
> This will work no matter which O/S you have.
Yes, I think that this style is a way which we can take.
But the problem will occur when a new protocol family(ex. IPv7) is created.
In the time we have to modify this code....
If sctp_get[lp]addrs return sockaddrs's length, we wlll not have to modify it
using getnameinfo() which we improve separately for IPv7.
In a dynamic linking binary, we can change getnameinfo() easily.

This style is Protocol Independent Programing.
	http://www.mew.org/~kazu/doc/piprog.html
I think that the standard specification should be created to enable this style.
The current functions, getsockname(), getpeername(), return sockaddr's length
to enable it. (I can't check wheter theses were created to enable it or not:)
So, sctp_get[lp]addrs() should return sockaddr's length, I think.

Regards, Masahiro.
-- 
{^-^}/@kozuka.jp / KOZUKA Masahiro

---

From: Kacheong Poon <[email-masked]>
Date: Fri, 26 Mar 2004 14:45:10 -0800

> In the time we have to modify this code....

I guess it depends.  The reason is that the array returned by
sctp_get*addrs() is a fixed array.  The length of each element
in the array is determined by the socket type.  So if your code
makes use of this fact and have a pre-determined length variable
based on the socket type, it can then be used to call getnameinfo().
When there is an IPv7, the code should still work, assuming IPv7 has
the same compatibility mode as in IPv6.  You don't need to modify
your code to handle that.

> So, sctp_get[lp]addrs() should return sockaddr's length, I think.

The situation is a little bit different when, for example
getsockname(), only needs to deal with one single address.
We are dealing with a list of addresses.  And the fact
that getsockname() also works for, say UNIX domain socket.
The address (a pathname) length itself is a variable.  It
has to take a length parameter.  For SCTP, the API only
supports IPv4/v6 socket.  So the length of the address is
pre-determined and code can make use of this fact.

-- 

						K. Poon.
						[email-masked]