Re: getservbyport (fwd)

Jos Vos (jos@xos.nl)
Tue, 14 May 1996 16:56:51 +0200 (MET DST)


> I've got the question: why this produces shit! ?
>
> #include <stdio.h>
> #include <netdb.h>
>
> main() {
> struct servent *serv;
> if ((serv = getservbyport(23, "tcp")) == NULL) {
> printf("shit!\n");
> } else {
> printf("name: %s\n", serv->s_name);
> }
> }

Use:

if ((serv = getservbyport(htons(23), "tcp")) == NULL) {

And it _might_ also go wrong with old libc's, even if you use htons().

-- 
--    Jos Vos <jos@xos.nl>
--    X/OS Experts in Open Systems BV   |   Phone: +31 20 6938364
--    Amsterdam, The Netherlands        |     Fax: +31 20 6948204