Mercurial > dovecot > core-2.2
diff src/lib/network.c @ 11926:10c4c9d5fb5b
net_accept(), net_getsock/peername(): Return UNIX sockets with family=port=0.
A lot of checks inside our code assumes that family is either AF_INET,
AF_INET6 or 0. struct ip_addr doesn't support anything else either, so having
AF_UNIX as family but without a way to get the socket name from the struct
isn't very helpful either.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 04 Aug 2010 15:06:05 +0100 |
parents | 4fb7e5327efc |
children | e403f4dc95ea |
line wrap: on
line diff
--- a/src/lib/network.c Wed Aug 04 13:49:54 2010 +0100 +++ b/src/lib/network.c Wed Aug 04 15:06:05 2010 +0100 @@ -504,10 +504,13 @@ else return -2; } - - if (addr != NULL) sin_get_ip(&so, addr); - if (port != NULL) *port = sin_get_port(&so); - + if (so.sin.sin_family == AF_UNIX) { + if (addr != NULL) addr->family = 0; + if (port != NULL) *port = 0; + } else { + if (addr != NULL) sin_get_ip(&so, addr); + if (port != NULL) *port = sin_get_port(&so); + } return ret; } @@ -630,10 +633,13 @@ addrlen = sizeof(so); if (getsockname(fd, &so.sa, &addrlen) == -1) return -1; - - if (addr != NULL) sin_get_ip(&so, addr); - if (port != NULL) *port = sin_get_port(&so); - + if (so.sin.sin_family == AF_UNIX) { + if (addr != NULL) addr->family = 0; + if (port != NULL) *port = 0; + } else { + if (addr != NULL) sin_get_ip(&so, addr); + if (port != NULL) *port = sin_get_port(&so); + } return 0; } @@ -647,10 +653,13 @@ addrlen = sizeof(so); if (getpeername(fd, &so.sa, &addrlen) == -1) return -1; - - if (addr != NULL) sin_get_ip(&so, addr); - if (port != NULL) *port = sin_get_port(&so); - + if (so.sin.sin_family == AF_UNIX) { + if (addr != NULL) addr->family = 0; + if (port != NULL) *port = 0; + } else { + if (addr != NULL) sin_get_ip(&so, addr); + if (port != NULL) *port = sin_get_port(&so); + } return 0; }