Subject: Re: Strange behavious of getpeername(2) on pipe
To: None <tech-kern@netbsd.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-kern
Date: 03/27/2001 09:28:52
[replying to some three or four messages at once, here]

> Is it normal for a call to getpeername(2) on a non-socket (a pipe,
> more specifically)

Pipes are not non-sockets, as others have pointed out.  See sys_pipe,
in kern/uipc_syscalls.c.

> note that in NetBSD, pipe() is really a frontend for socketpair(),

Well...sort of.  pipe() is actually a syscall, but the implementation
bears, um, "remarkable similarities" to socketpair()'s.

> so the fd's you get back from pipe are really sockets.

...but this *is* true.

> Also it is better to use "struct sockaddr_storage" for getpeername(2)
> storage.

Where is this documented?  This is the first I've ever heard of
sockaddr_storage.

> And is there _any_ possibility of discerning whether a given fd is a
> socket or a pipe?

No.  With the current implementation, this makes about as much sense as
trying to discern whether a file descriptor was opened via open() or
dup(): the distinction you are trying to draw simply does not exist.

Whether this is good or not is a question I do not wish to address.

					der Mouse

			       mouse@rodents.montreal.qc.ca
		     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B