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;
}
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;
}
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;
}
again. */
int net_listen_unix_unlink_stale(const char *path, int backlog);
/* Accept a connection on a socket. Returns -1 if the connection got closed,
- -2 for other failures */
+ -2 for other failures. For UNIX sockets addr->family=port=0. */
int net_accept(int fd, struct ip_addr *addr, unsigned int *port);
/* Read data from socket, return number of bytes read,
some error with name server) */
int net_hosterror_notfound(int error) ATTR_CONST;
-/* Get socket local address/port */
+/* Get socket local address/port. For UNIX sockets addr->family=port=0. */
int net_getsockname(int fd, struct ip_addr *addr, unsigned int *port);
-/* Get socket remote address/port */
+/* Get socket remote address/port. For UNIX sockets addr->family=port=0. */
int net_getpeername(int fd, struct ip_addr *addr, unsigned int *port);
/* Get UNIX socket name. */
int net_getunixname(int fd, const char **name_r);