Subject: lib/34744: Missing documentation of struct sockaddr member "sun_len" in unix(4)
To: None <lib-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: Christian Biere <christianbiere@gmx.de>
List: netbsd-bugs
Date: 10/07/2006 16:15:01
>Number:         34744
>Category:       lib
>Synopsis:       Missing documentation of struct sockaddr member "sun_len" in unix(4)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          doc-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Oct 07 16:15:00 +0000 2006
>Originator:     Christian Biere
>Release:        NetBSD 4.99.3
>Environment:
System: NetBSD cyclonus 4.99.3 NetBSD 4.99.3 (STARSCREAM) #0: Mon Oct 2 23:04:22 CEST 2006 src@cyclonus:/o/NetBSD/obj/sys/arch/i386/compile/STARSCREAM i386
Architecture: i386
Machine: i386
>Description:
The manpage unix(4) does not document how "sun_len" should be used. It would also be
nice to document this in a portable manner. For example, many systems don't have
this struct member nor the macro SUN_LEN. I use

	static struct sockaddr_un zero_un;
	struct sockaddr_un un = zero_un;
	...

Others may prefer 

	memset(un, 0, sizeof un);

This way the existence or non-existence of sun_len is irrelevant. This works
apparently on NetBSD. I don't know whether some systems require proper
initialization of "sun_len" and if so what's the correct way to set it.

strlen(un.sun_path)? SUN_LEN(&un)?

Additionally, it might be useful to show some examples for connect() and bind()

	bind(fd, un, SUN_LEN(&un));
	connect(fd, un, SUN_LEN(&un));

The manpage mentions it but it's easy to overread, especially as this might
be unexpected, because usually you just pass "sizeof some_socket_struct".
Last but not least, one might wonder what to pass to getsockname().

>How-To-Repeat:
>Fix: