🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #880

Re: binding sockets

#880
From: Chris Torek
Date: Thu, 20 Sep 1990 14:47
36 lines
1738 bytes
>In article <26618@mimsy.umd.edu> I wrote:
>>[namelen] `should' be 2+strlen(path), or (in 4.3BSD-reno) SUN_LEN:

In article <3580@awdprime.UUCP>
jeffe@sandino.austin.ibm.com (Peter Jeffe 512.823.4091) writes:
>Not to quibble, but it `should' be "sizeof(name.sun_family)+strlen(path)";

Not so---and I specifically wrote `2' to avoid this---because in
4.3BSD-reno the result will be one byte too short.  (You must also
include sizeof(name.sun_len), which is 1.)

>or better yet, "sizeof(name)-sizeof(name.sun_path)+strlen(path)";

This will work, and is how SUN_LEN is defined.

>in any case, assuming the 2 bytes is not a good idea.

Recommendation: add the following to your code, and then use SUN_LEN.

#ifndef SUN_LEN
/* actual length of an initialized sockaddr_un */
#define SUN_LEN(su) \
	(sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
#endif


>
>-------------------------------------------------------------------------------
>Peter Jeffe   ...uunet!cs.utexas.edu!ibmaus!auschs!sandino.austin.ibm.com!jeffe
>        first they want a disclaimer, then they make you pee in a jar,
>                   then they come for you in the night


-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750)
Domain:	chris@cs.umd.edu	Path:	uunet!mimsy!chris
Technical Details
Message-ID: <26634@mimsy.umd.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!aplcen!uakari.primate.wisc.edu!ark1!oasys!mimsy!chris
References: <ERAN.90Sep14115242@elaine7.stanford.edu> <3580@awdprime.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!aplcen!uakari.primate.wisc.edu!ark1!oasys!mimsy!chris
From: chris@mimsy.umd.edu (Chris Torek)
Newsgroups: comp.unix.programmer
Subject: Re: binding sockets
Message-ID: <26634@mimsy.umd.edu>
Date: 20 Sep 90 14:47:44 GMT
References: <ERAN.90Sep14115242@elaine7.stanford.edu> <3580@awdprime.UUCP>
Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742
Lines: 36