summaryrefslogtreecommitdiffstats
path: root/libc/netbsd
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@google.com>2009-05-26 23:54:37 +0200
committerDavid 'Digit' Turner <digit@google.com>2009-05-27 00:01:11 +0200
commit2735b33519595da5d51b79757ccce730021a9228 (patch)
tree7839125a9beb3a38e33950d22b5495a3ab66c19d /libc/netbsd
parent8215679b355efe3829bab571bd566dc818ea4ccc (diff)
downloadbionic-2735b33519595da5d51b79757ccce730021a9228.zip
bionic-2735b33519595da5d51b79757ccce730021a9228.tar.gz
bionic-2735b33519595da5d51b79757ccce730021a9228.tar.bz2
Fix getservent() so that it returns s_port in network byte order.
Also add a new document detailing known issues in the C library.
Diffstat (limited to 'libc/netbsd')
-rw-r--r--libc/netbsd/net/getservent.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/libc/netbsd/net/getservent.c b/libc/netbsd/net/getservent.c
index 45207df..65fbd7e 100644
--- a/libc/netbsd/net/getservent.c
+++ b/libc/netbsd/net/getservent.c
@@ -27,6 +27,7 @@
*/
#include <sys/cdefs.h>
#include <sys/types.h>
+#include <sys/endian.h>
#include <netdb.h>
#include "servent.h"
#include "services.h"
@@ -54,6 +55,7 @@ getservent_r( res_static rs )
int namelen;
int nn,count;
int total = 0;
+ int port;
char* p2;
p = rs->servent_ptr;
@@ -92,9 +94,12 @@ getservent_r( res_static rs )
memcpy( rs->servent.s_name, p+1, namelen );
rs->servent.s_name[namelen] = 0;
p += 1 + namelen;
- rs->servent.s_port = ((((unsigned char*)p)[0] << 8) |
- ((unsigned char*)p)[1]);
+ /* s_port must be in network byte order */
+ port = ((((unsigned char*)p)[0] << 8) |
+ ((unsigned char*)p)[1]);
+
+ rs->servent.s_port = htons(port);
rs->servent.s_proto = p[2] == 't' ? "tcp" : "udp";
p += 4; /* skip port(2) + proto(1) + aliascount(1) */