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

I suppose it is _way_ to late to fix, but I have to wonder why
getservbyport() doesn't do the conversion itself. A library
running on a little-endian machine should not require the
programmer to mess with htons() at all.

It almost looks like something a vendor designed to make it
difficult to write portable programs. (If you only have a
Sun, that's where you test your program for bugs.)


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