* 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.
This commit is contained in:
Corinna Vinschen 2002-01-01 16:25:31 +00:00
parent b346ae85d6
commit 2fe2790925
5 changed files with 5384 additions and 5341 deletions

File diff suppressed because it is too large Load Diff

5333
winsup/cygwin/ChangeLog-2001 Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/* fhandler.h
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.
@ -360,6 +360,7 @@ class fhandler_socket: public fhandler_base
int connect_secret [4];
HANDLE secret_event;
struct _WSAPROTOCOL_INFOA *prot_info_ptr;
char *sun_path;
public:
fhandler_socket ();
@ -392,6 +393,8 @@ class fhandler_socket: public fhandler_base
select_record *select_except (select_record *s);
int get_addr_family () {return addr_family;}
void set_addr_family (int af) {addr_family = af;}
void set_sun_path (const char *path);
char *get_sun_path () {return sun_path;}
void set_connect_secret ();
void get_connect_secret (char*);
HANDLE create_secret_event (int *secret = NULL);

View File

@ -1,6 +1,6 @@
/* fhandler_socket.cc. See fhandler.h for a description of the fhandler classes.
Copyright 2000, 2001 Red Hat, Inc.
Copyright 2000, 2001, 2002 Red Hat, Inc.
This file is part of Cygwin.
@ -42,7 +42,7 @@ fhandler_dev_random* entropy_source;
/* fhandler_socket */
fhandler_socket::fhandler_socket ()
: fhandler_base (FH_SOCKET)
: fhandler_base (FH_SOCKET), sun_path (NULL)
{
set_need_fork_fixup ();
prot_info_ptr = (LPWSAPROTOCOL_INFOA) cmalloc (HEAP_BUF,
@ -53,6 +53,8 @@ fhandler_socket::~fhandler_socket ()
{
if (prot_info_ptr)
cfree (prot_info_ptr);
if (sun_path)
cfree (sun_path);
}
void
@ -478,3 +480,11 @@ fhandler_socket::set_close_on_exec (int val)
set_close_on_exec_flag (val);
debug_printf ("set close_on_exec for %s to %d", get_name (), val);
}
void
fhandler_socket::set_sun_path (const char *path)
{
if (sun_path)
cfree (sun_path);
sun_path = cstrdup (path);
}

View File

@ -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;