lkml.org 
[lkml]   [1996]   [May]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: getservbyport (fwd)
Date
> 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


\
 
 \ /
  Last update: 2005-03-22 13:37    [W:0.509 / U:0.824 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site