diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2002-01-01 16:25:31 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2002-01-01 16:25:31 +0000 |
commit | 2fe2790925a73a7e8e7e7a27c413cd6fefd15e73 (patch) | |
tree | a27b61984317b0d26543e3f9ec5a0411cae5c4fd /winsup/cygwin/net.cc | |
parent | b346ae85d61545513c4dea0fe44e5e3dc1524c66 (diff) | |
download | newlib-2fe2790925a73a7e8e7e7a27c413cd6fefd15e73.zip newlib-2fe2790925a73a7e8e7e7a27c413cd6fefd15e73.tar.gz newlib-2fe2790925a73a7e8e7e7a27c413cd6fefd15e73.tar.bz2 |
* fhandler.h (fhandler_socket::sun_path): New private member.
(fhandler_socket::set_sun_path): New method.
(fhandler_socket::get_sun_path): Ditto.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Initialize
sun_path to NULL.
(fhandler_socket::~fhandler_socket): Free sun_path if needed.
(fhandler_socket::set_sun_path): New method.
* net.cc (cygwin_bind): Set sun_path to path of local socket file.
(cygwin_getsockname): Add code to return correct sockaddr for unix
domain sockets.
Diffstat (limited to 'winsup/cygwin/net.cc')
-rw-r--r-- | winsup/cygwin/net.cc | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 6701269..9e02085 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -1,6 +1,6 @@ /* net.cc: network-related routines. - Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc. + Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -1338,6 +1338,7 @@ cygwin_bind (int fd, const struct sockaddr *my_addr, int addrlen) _close (fd); chmod (un_addr->sun_path, (S_IFSOCK | S_IRWXU | S_IRWXG | S_IRWXO) & ~cygheap->umask); + sock->set_sun_path (un_addr->sun_path); res = 0; } #undef un_addr @@ -1366,10 +1367,27 @@ cygwin_getsockname (int fd, struct sockaddr *addr, int *namelen) fhandler_socket *sock = get (fd); if (sock) { - res = getsockname (sock->get_socket (), addr, namelen); - if (res) - set_winsock_errno (); - + if (sock->get_addr_family () == AF_UNIX) + { + struct sockaddr_un *sun = (struct sockaddr_un *) addr; + memset (sun, 0, *namelen); + sun->sun_family = AF_UNIX; + /* According to SUSv2 "If the actual length of the address is greater + than the length of the supplied sockaddr structure, the stored + address will be truncated." We play it save here so that the + path always has a trailing 0 even if it's truncated. */ + strncpy (sun->sun_path, sock->get_sun_path (), + *namelen - sizeof *sun + sizeof sun->sun_path - 1); + *namelen = sizeof *sun - sizeof sun->sun_path + + strlen (sun->sun_path) + 1; + res = 0; + } + else + { + res = getsockname (sock->get_socket (), addr, namelen); + if (res) + set_winsock_errno (); + } } syscall_printf ("%d = getsockname (%d, %x, %d)", res, fd, addr, namelen); return res; |