diff options
author | Philip Guenthe <guenther@cvs.openbsd.org> | 2012-10-12 20:45:50 +0000 |
---|---|---|
committer | Philip Guenthe <guenther@cvs.openbsd.org> | 2012-10-12 20:45:50 +0000 |
commit | 88126658e3062e58c4d0c9964df9da01ca99690c (patch) | |
tree | f986f526f0e7f60741beb8fdbc470675c6db0735 | |
parent | 15e03b4a463ed6ed94dfb27d1c84e3a97d13bbc0 (diff) |
For consistency with other OSes and ease of porting, make
get{sock,peer}name() behave like accept() when the involved UNIX-domain
socket isn't bound to an address, returning an AF_UNIX sockaddr
with zero-length sun_path. Based on diff from robert@ and mikeb@
ok robert@ deraadt@
-rw-r--r-- | lib/libc/sys/getsockname.2 | 10 | ||||
-rw-r--r-- | sys/kern/uipc_usrreq.c | 41 |
2 files changed, 22 insertions, 29 deletions
diff --git a/lib/libc/sys/getsockname.2 b/lib/libc/sys/getsockname.2 index c246b7350f0..c64b09ccb07 100644 --- a/lib/libc/sys/getsockname.2 +++ b/lib/libc/sys/getsockname.2 @@ -1,4 +1,4 @@ -.\" $OpenBSD: getsockname.2,v 1.27 2010/07/01 20:48:37 jmc Exp $ +.\" $OpenBSD: getsockname.2,v 1.28 2012/10/12 20:45:49 guenther Exp $ .\" $NetBSD: getsockname.2,v 1.6 1995/10/12 15:41:00 jtc Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)getsockname.2 8.1 (Berkeley) 6/4/93 .\" -.Dd $Mdocdate: July 1 2010 $ +.Dd $Mdocdate: October 12 2012 $ .Dt GETSOCKNAME 2 .Os .Sh NAME @@ -156,9 +156,3 @@ The .Fn getsockname function call appeared in .Bx 4.2 . -.Sh BUGS -Names bound to sockets in the -.Ux Ns -domain -are inaccessible; -.Nm getsockname -returns a zero length name. diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index d126b85742c..849b40c6576 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_usrreq.c,v 1.68 2012/09/02 05:20:17 deraadt Exp $ */ +/* $OpenBSD: uipc_usrreq.c,v 1.69 2012/10/12 20:45:49 guenther Exp $ */ /* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */ /* @@ -48,6 +48,8 @@ #include <sys/stat.h> #include <sys/mbuf.h> +void uipc_setaddr(const struct unpcb *, struct mbuf *); + /* * Unix communications domain. * @@ -59,6 +61,20 @@ struct sockaddr sun_noname = { sizeof(sun_noname), AF_UNIX }; ino_t unp_ino; /* prototype for fake inode numbers */ +void +uipc_setaddr(const struct unpcb *unp, struct mbuf *nam) +{ + if (unp != NULL && unp->unp_addr != NULL) { + nam->m_len = unp->unp_addr->m_len; + bcopy(mtod(unp->unp_addr, caddr_t), mtod(nam, caddr_t), + nam->m_len); + } else { + nam->m_len = sizeof(sun_noname); + bcopy(&sun_noname, mtod(nam, struct sockaddr *), + nam->m_len); + } +} + /*ARGSUSED*/ int uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, @@ -119,14 +135,7 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, * if it was bound and we are still connected * (our peer may have closed already!). */ - if (unp->unp_conn && unp->unp_conn->unp_addr) { - nam->m_len = unp->unp_conn->unp_addr->m_len; - bcopy(mtod(unp->unp_conn->unp_addr, caddr_t), - mtod(nam, caddr_t), nam->m_len); - } else { - nam->m_len = sizeof(sun_noname); - *(mtod(nam, struct sockaddr *)) = sun_noname; - } + uipc_setaddr(unp->unp_conn, nam); break; case PRU_SHUTDOWN: @@ -283,21 +292,11 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, break; case PRU_SOCKADDR: - if (unp->unp_addr) { - nam->m_len = unp->unp_addr->m_len; - bcopy(mtod(unp->unp_addr, caddr_t), - mtod(nam, caddr_t), nam->m_len); - } else - nam->m_len = 0; + uipc_setaddr(unp, nam); break; case PRU_PEERADDR: - if (unp->unp_conn && unp->unp_conn->unp_addr) { - nam->m_len = unp->unp_conn->unp_addr->m_len; - bcopy(mtod(unp->unp_conn->unp_addr, caddr_t), - mtod(nam, caddr_t), nam->m_len); - } else - nam->m_len = 0; + uipc_setaddr(unp->unp_conn, nam); break; case PRU_SLOWTIMO: |