diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-12 10:35:23 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-12 10:35:23 +0000 |
commit | 6536a9b5833febe719988526a095a9cacb8a1042 (patch) | |
tree | 07b65c5cf7e1f51909d4e7b516253bae7611fa48 /libbb/xconnect.c | |
parent | f8138d1f91c913166bffb0077a0fe06831a77ecf (diff) | |
download | busybox-w32-6536a9b5833febe719988526a095a9cacb8a1042.tar.gz busybox-w32-6536a9b5833febe719988526a095a9cacb8a1042.tar.bz2 busybox-w32-6536a9b5833febe719988526a095a9cacb8a1042.zip |
next part of ipv6-ization is here: wget & httpd
Diffstat (limited to 'libbb/xconnect.c')
-rw-r--r-- | libbb/xconnect.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/libbb/xconnect.c b/libbb/xconnect.c index a5b16d982..f5a7e6dc8 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c | |||
@@ -38,7 +38,7 @@ void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) | |||
38 | * default_port */ | 38 | * default_port */ |
39 | unsigned bb_lookup_port(const char *port, const char *protocol, unsigned default_port) | 39 | unsigned bb_lookup_port(const char *port, const char *protocol, unsigned default_port) |
40 | { | 40 | { |
41 | unsigned port_nr = htons(default_port); | 41 | unsigned port_nr = default_port; |
42 | if (port) { | 42 | if (port) { |
43 | int old_errno; | 43 | int old_errno; |
44 | 44 | ||
@@ -49,13 +49,11 @@ unsigned bb_lookup_port(const char *port, const char *protocol, unsigned default | |||
49 | if (errno || port_nr > 65535) { | 49 | if (errno || port_nr > 65535) { |
50 | struct servent *tserv = getservbyname(port, protocol); | 50 | struct servent *tserv = getservbyname(port, protocol); |
51 | if (tserv) | 51 | if (tserv) |
52 | port_nr = tserv->s_port; | 52 | port_nr = ntohs(tserv->s_port); |
53 | } else { | ||
54 | port_nr = htons(port_nr); | ||
55 | } | 53 | } |
56 | errno = old_errno; | 54 | errno = old_errno; |
57 | } | 55 | } |
58 | return port_nr; | 56 | return (uint16_t)port_nr; |
59 | } | 57 | } |
60 | 58 | ||
61 | 59 | ||
@@ -148,7 +146,7 @@ static len_and_sockaddr* str2sockaddr(const char *host, int port, int ai_flags) | |||
148 | r = xmalloc(offsetof(len_and_sockaddr, sa) + result->ai_addrlen); | 146 | r = xmalloc(offsetof(len_and_sockaddr, sa) + result->ai_addrlen); |
149 | r->len = result->ai_addrlen; | 147 | r->len = result->ai_addrlen; |
150 | memcpy(&r->sa, result->ai_addr, result->ai_addrlen); | 148 | memcpy(&r->sa, result->ai_addr, result->ai_addrlen); |
151 | set_port(r, port); | 149 | set_port(r, htons(port)); |
152 | freeaddrinfo(result); | 150 | freeaddrinfo(result); |
153 | return r; | 151 | return r; |
154 | } | 152 | } |
@@ -237,6 +235,7 @@ static char* sockaddr2str(const struct sockaddr *sa, socklen_t salen, int flags) | |||
237 | flags | NI_NUMERICSERV /* do not resolve port# */ | 235 | flags | NI_NUMERICSERV /* do not resolve port# */ |
238 | ); | 236 | ); |
239 | if (rc) return NULL; | 237 | if (rc) return NULL; |
238 | // We probably need to use [%s]:%s for IPv6... | ||
240 | return xasprintf("%s:%s", host, serv); | 239 | return xasprintf("%s:%s", host, serv); |
241 | } | 240 | } |
242 | 241 | ||