🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #35404

Re: nnrpd daemon (-D) mode fixes

#35404
From: Andrew Gierth
Date: Fri, 12 Feb 1999 00:00
46 lines
2964 bytes
>>>>> "bill" == bill davidsen <davidsen@tmr.com> writes:

 [Forrest]
 > | Bill, your "corrected" code fails if a sizeof(sockaddr_in) is
 > | larger than sizeof(sockaddr).  (What should happen is that
 > | accept() would see a wrong length member and return an error.)

 bill> Then perhaps the prototype is wrong, since it requires sockaddr.

The prototype is perhaps misleading, but it's not wrong.

Consider the use of other address families with accept() et. al. The
actual type of address structure passed might be any one of sockaddr_in,
sockaddr_un, sockaddr_in6, sockaddr_???...

The prototype can't specify any single one of these types; that would
be clearly wrong. The only way to avoid casts would be for the
prototype to specify (void*) for the type instead; but that doesn't
tell you anything useful about what the parameter is supposed to
be. For whatever reason, the standards currently dictate that address
parameters are of type (struct sockaddr *), and casts are always
required when passing the address of an actual object.

(If you're writing protocol-independent code, then you wouldn't be
declaring a sockaddr structure of any flavour to use for an accept
call, but instead you'd have to use malloc() to allocate sufficient
space (as determined earlier when you bound the socket). Using
'struct sockaddr' would be wrong because many address families use
longer address structures. But nnrpd in its current form is not
protocol-independent.)

 bill> If so, it's wrong on a LOT of systems... which is why I assumed
 bill> that the prototype was correct and the source was wrong. If
 bill> that's the case it's wrong on at least Linux, BSD, SCO and AIX,
 bill> I checked there before I changed it.

From the Single Unix spec:

int accept (int socket, struct sockaddr *address, socklen_t *address_len);

(note that 'socklen_t' is relatively new, and 'int' is more common)

-- 
Andrew.

Technical Details
Message-ID: <87btizqtka.fsf@erlenstar.demon.co.uk>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
References: <79eufj$7nh0$1@newssvr04-int.news.prodigy.com> <873e4kprj6.fsf@erlenstar.demon.co.uk> <79smvr$7ni8$1@newssvr04-int.news.prodigy.com> <79t2ms$iil$1@news1.epix.net> <7a1t47$8rka$1@newssvr04-int.news.prodigy.com>

Show Full Headers
Complete Article Headers
Message-ID: <87btizqtka.fsf@erlenstar.demon.co.uk>
Subject: Re: nnrpd daemon (-D) mode fixes
Date: Fri, 12 Feb 1999 00:00:00 +0000
From: Andrew Gierth <andrew@erlenstar.demon.co.uk>
References: <79eufj$7nh0$1@newssvr04-int.news.prodigy.com> <873e4kprj6.fsf@erlenstar.demon.co.uk> <79smvr$7ni8$1@newssvr04-int.news.prodigy.com> <79t2ms$iil$1@news1.epix.net> <7a1t47$8rka$1@newssvr04-int.news.prodigy.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
X-Deja-AN: 443727066
X-Mayan-Date: Long count = 12.19.5.16.17; tzolkin = 11 Caban; haab = 10 Pax
X-Complaints-To: andrew@erlenstar.demon.co.uk
Organization: disorganised
X-Attribution: AG
X-Pgp-0x0E9FFBE9: 87 25 7F 14 41 24 B3 51 E0 19 8B DE 49 74 0C 29
X-P-Persistent-Headers: are a bad idea.
Newsgroups: news.software.nntp
X-Post-Filter: postfilter v0.01 alpha