[1257] in Athena Bugs

home help back first fref pref prev next nref lref last post

[chris@mimsy.umd.edu: Re: getpeername(2) on unix domain sockets?]

daemon@ATHENA.MIT.EDU (Mark W. Eichin)
Thu Oct 27 00:17:58 1988

Date: Thu, 27 Oct 88 00:17:37 EDT
From: Mark W. Eichin <eichin@ATHENA.MIT.EDU>
To: bugs@ATHENA.MIT.EDU
The code referred to here is in /paris/source/vax/sys/sys/uipc_usrreq.c after
line 252. We indeed do not have the fixes in our sources.

				Mark Eichin
			<eichin@athena.mit.edu>
		SIPB Member & Project Athena ``Watchmaker'' 

Date: 27 Oct 88 00:50:23 GMT
From: chris@mimsy.umd.edu  (Chris Torek)
Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742
Subject: Re: getpeername(2) on unix domain sockets?
References: <2743@ingr.UUCP>
Sender: xpert-request@ATHENA.MIT.EDU
To: xpert@ATHENA.MIT.EDU

In article <2743@ingr.UUCP> myoung@ingr.UUCP (Mark Young) writes:
>A test case on a bsd4.3 release demonstrates that a call to getpeername 
>specifying the fd for a unix domain socket returns success, with a 'namelen'
>that seems somewhat random.

Getpeername() on Unix domain sockets is broken in 4.3BSD.  The
behaviour you describe occurs on unconnected Unix domain sockets.
Getpeername() on connected Unix domain sockets crashes the machine.
Fixed in 4.3-tahoe, or apply the following to your kernel:

	[old]
	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(m, caddr_t), (unsigned)m->m_len);
		}
		break;

	[new]
	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), (unsigned)nam->m_len);
		} else
			nam->m_len = 0;

>I did note, however, that the function getsockname(2) does indeed list as 
>a bug:
>
>	Names bound to sockets in the UNIX domain are inaccessible;  
>	'getsockname' returns a zero length name.

The manual entry is wrong on both counts (not surprising)---the 4.3BSD
distribution kernel leaves the name length unmodified, due to another
kernel bug.  Right above the case PRU_PEERADDR, you will find

	case PRU_SOCKADDR:
		break;

which should read

	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), (unsigned)nam->m_len);
		} else
			nam->m_len = 0;
		break;

(exactly analagous to the case for PRU_PEERADDR).
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris

home help back first fref pref prev next nref lref last post