[PHP-DEV] Re: getsockname() semantics From: Sascha Schumann (sascha <email protected>)
Date: 09/23/00

On Fri, 22 Sep 2000, Stig Venaas wrote:

> In some situations it would be nice to have a way to determine the
> domain of an existing socket. On all implementations I've checked
> getsockname() will for PF_INET and PF_INET6, return the respective
> family in the sockaddr structure, even when the socket is not bound
> to a local name (calling getsockname() right after socket()). This
> is not the case for PF_LOCAL.
>
> I've seen several examples where people use this, even though it is
> not specified in any standard AFAIK.
>
>
> In the July 31 draft it says:
>
> If the socket has not been bound to a local name, the value stored
> in the object pointed to by address is unspecified.
>
>
> Would it be possible to change this? If not, is there some other
> portable way to determine the domain?
>
> I haven't followed this list and the groups work all that long,
> sorry if this is not the right way or place to bring this up.
>
> Stig
>
> --
> Stig Venaas
> UNINETT
>

    This reminds me of some ugliness in the sockets' extension
    code.

    The code uses getsockname() to determine the address family
    of the socket. It passes a pointer to a sockaddr structure to
    getsockname() under the assumption that the sockaddr
    structure is large enough to accommodate all supported
    protocol-specific address structures. This assumption is
    false.

    The right way to do this is to use the sockaddr_storage
    structure. If that structure is not available, fall back to
    the sockaddr structure for compatibility with existing
    implementations.

    - Sascha

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>