From 88126658e3062e58c4d0c9964df9da01ca99690c Mon Sep 17 00:00:00 2001 From: Philip Guenthe Date: Fri, 12 Oct 2012 20:45:50 +0000 Subject: 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@ --- sys/kern/uipc_usrreq.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'sys/kern') 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 #include +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: -- cgit v1.2.3