The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] void *, caddr_t and struct sockaddr* in 4.1x and 4.2 BSD
@ 2017-11-07 10:44 Paul Ruizendaal
  2017-11-07 15:29 ` Don Hopkins
  0 siblings, 1 reply; 2+ messages in thread
From: Paul Ruizendaal @ 2017-11-07 10:44 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2555 bytes --]

Many thanks for all that background to the origins of void pointers.

Now for applying that to the early sockets API.

In the first (1981) and second (4.1a, April 1982) revision of that API, socket addresses were passed as a fixed 16-byte structure, essentially the same as the current struct sockaddr. By the time of the third revision (4.1c/4.2, 1983) of that API it had become a variable sized opaque object, passed around as a pointer and a size.

The 1983 4.2BSD system manual (http://www.cilinder.be/docs/bsd/4.2BSD_Unix_system_manual.pdf) describes it that way, e.g. defining connect() as:

connect(s, name, namelen);
        int s; caddr_t name; int namelen;

Note the use of caddr_t in the user level signature. Yet, the actual source code for 4.1c/4.2 BSD only uses caddr_t in the kernel (as pointed out on this list), but continues to use struct sockaddr * in the user land interface. It would seem to me today that void * would have been a more logical choice and with void * having been around for about 3 years in 1983, it might have seemed logical back then as well -- after all, this use case is similar to the malloc() use case. It would have avoided the need for a longish type cast in socket api calls (without further loss of type safety, as that was already lost with the required cast from e.g. struct sockaddr_un* to struct sockaddr* anyway).

Related to this, from the "4.2bsd IPC Primer” (1983, https://www2.eecs.berkeley.edu/Pubs/TechRpts/1983/CSD-83-145.pdf , page 5), it would appear that the format of socket addresses was perhaps unfinished business:

- Apparently at some point in time simple strings were considered as unix domain addresses, i.e. not a sockaddr_un structure. Maybe it was limping on this thought that caused the prototype soackaddr structure not to have a size field — having had that would have simplified the signature of many socket API functions (interestingly, it would seem that such a size field was added in 4.3BSD some 6, 7 years later).

- The examples show no type casts. This may have been for didactical clarity, but perhaps it also suggests a signature with void* semantics.

I’d be happy for any background on this.

Also, about halfway down this page http://tech-insider.org/vms/research/1982/0111.html there is mention of CSRG technical report #4, "CSRG TR/4 (Proposals for the Enhancement of Unix on the Vax)”. I think this may be the initial discussion document from the summer of 1981 that evolved into the 4.2 system manual. Would anybody have a copy of that document?

Paul



^ permalink raw reply	[flat|nested] 2+ messages in thread

* [TUHS] void *, caddr_t and struct sockaddr* in 4.1x and 4.2 BSD
  2017-11-07 10:44 [TUHS] void *, caddr_t and struct sockaddr* in 4.1x and 4.2 BSD Paul Ruizendaal
@ 2017-11-07 15:29 ` Don Hopkins
  0 siblings, 0 replies; 2+ messages in thread
From: Don Hopkins @ 2017-11-07 15:29 UTC (permalink / raw)


> It would seem to me today that void * would have been a more logical choice

Not just logical: A pointer into the void seems like an aesthetically perfect type for a network address.

-Don



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-11-07 15:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-07 10:44 [TUHS] void *, caddr_t and struct sockaddr* in 4.1x and 4.2 BSD Paul Ruizendaal
2017-11-07 15:29 ` Don Hopkins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).