Re: getsockname() semantics

From: Date: Sun, 24 Sep 2000 06:48:04 +0000
Subject: Re: getsockname() semantics
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-33636@lists.php.net to get a copy of this message
On Sat, 23 Sep 2000, Stig Venaas wrote: > On Sat, Sep 23, 2000 at 09:14:50PM +0200, Sascha Schumann wrote: > > This reminds me of some ugliness in the sockets' extension > > code. > > Yes, there are some other ugly stuff there too. > > > The code uses getsockname() to determine the address family > > of the socket. It passes a pointer to a sockaddr structure to > > It checks the family to determine if it's AF_INET or AF_UNIX. > If I on FreeBSD, Digital Unix or IRIX create an AF_UNIX socket > and immediately call getsockname, I don't get AF_UNIX as the > family. Just a manifestation of "don't rely on undefined behaviour." > I think we might need to store the type internally when the socket > is created. Safer and faster. I have not had a complete look at the module, but we might be able to reuse/merge some code from the socket buffering system (ext/standard/fsock.c). > > 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. > > What about falling back to sockaddr_un? That would be ok, if sockaddr_un would be guaranteed to be the largest structure. However, if we take this route, we might do something like this: #define PHP_S_UN sizeof(struct sockaddr_un) #define PHP_S_IN sizeof(struct sockaddr_in) #define PHP_S_IN6 sizeof(struct sockaddr_in6) #define PHP_SOCKADDR_SIZE MAX3(PHP_S_UN, PHP_S_IN, PHP_S_IN6) typedef unsigned char php_sockaddr_storage[PHP_SOCKADDR_SIZE]; - Sascha

« previous php.dev (#33636) next »