summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2012-10-12 20:45:50 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2012-10-12 20:45:50 +0000
commit88126658e3062e58c4d0c9964df9da01ca99690c (patch)
treef986f526f0e7f60741beb8fdbc470675c6db0735 /sys/kern
parent15e03b4a463ed6ed94dfb27d1c84e3a97d13bbc0 (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@
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/uipc_usrreq.c41
1 files changed, 20 insertions, 21 deletions
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: