lkml.org 
[lkml]   [1996]   [May]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: getservbyport (fwd)
> From owner-linux-kernel-outgoing@vger.rutgers.edu  Tue May 14 14:58:03 1996
> Date: Tue, 14 May 1996 02:28:04 +0200 (MET DST)
> From: Bartlomiej Czardybon <czar@dumb.iinf.polsl.gliwice.pl>
> Subject: getservbyport (fwd)
>
> 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);
> }
> }

Because you need to put the port number in network format. Replace
your query line with:

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

No, it doesn't make it clear in the man page!

Regards,

- Karl Keyte -------------------+-------------------------------------
European Space Agency | Private: Erbacher Strasse 6
Robert-Bosch Strasse 5 | D-64283 Darmstadt, Germany
64293 Darmstadt, Germany | Tel: +(49) 6151 22738
Tel: +(49) 6151 902041 | Fax: +(49) 6151 151319
Fax: +(49) 6151 903414 | Mobile: +(49) 172 6723741
e-Mail: kkeyte@esoc.esa.de | e-Mail: karl@koft.rhein-main.de
--------------------------------+-------------------------------------


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