extern void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
extern void xlisten(int s, int backlog);
extern void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen);
-extern int xconnect_tcp_v4(struct sockaddr_in *s_addr);
-extern struct hostent *xgethostbyname(const char *name);
-extern struct hostent *xgethostbyname2(const char *name, int af);
extern int setsockopt_reuseaddr(int fd);
extern int setsockopt_broadcast(int fd);
-
-/* "new" (ipv4+ipv6) API */
+/* NB: returns port in host byte order */
+unsigned bb_lookup_port(const char *port, const char *protocol, unsigned default_port);
typedef struct len_and_sockaddr {
int len;
union {
* UNIX socket address being returned, IPX sockaddr etc... */
extern len_and_sockaddr* host2sockaddr(const char *host, int port);
/* Assign sin[6]_port member if the socket is of corresponding type,
- * otherwise noop. Useful for ftp.
+ * otherwise no-op. Useful for ftp.
* NB: does NOT do htons() internally, just direct assignment. */
extern void set_nport(len_and_sockaddr *lsa, unsigned port);
-/* Retrieve sin[6]_port or return -1 for non-inet lsa's */
+/* Retrieve sin[6]_port or return -1 for non-INET[6] lsa's */
extern int get_nport(len_and_sockaddr *lsa);
extern char* xmalloc_sockaddr2host(const struct sockaddr *sa, socklen_t salen);
extern char* xmalloc_sockaddr2dotted(const struct sockaddr *sa, socklen_t salen);
+// "old" (ipv4 only) API
+//void bb_lookup_host(struct sockaddr_in *s_in, const char *host);
+//extern int xconnect_tcp_v4(struct sockaddr_in *s_addr);
+// users: traceroute.c hostname.c ifconfig.c ping.c
+extern struct hostent *xgethostbyname(const char *name);
+// ping6 is the only user - convert to new API
+extern struct hostent *xgethostbyname2(const char *name, int af);
extern char *xstrdup(const char *s);
int inflate(int in, int out);
-/* NB: returns port in host byte order */
-unsigned bb_lookup_port(const char *port, const char *protocol, unsigned default_port);
-void bb_lookup_host(struct sockaddr_in *s_in, const char *host);
-
int bb_make_directory(char *path, long mode, int flags);
int get_signum(const char *name);
/* "Old" networking API - only IPv4 */
-
+/*
void bb_lookup_host(struct sockaddr_in *s_in, const char *host)
{
struct hostent *he;
memcpy(&(s_in->sin_addr), he->h_addr_list[0], he->h_length);
}
+
int xconnect_tcp_v4(struct sockaddr_in *s_addr)
{
int s = xsocket(AF_INET, SOCK_STREAM, 0);
xconnect(s, (struct sockaddr*) s_addr, sizeof(*s_addr));
return s;
}
-
+*/
/* "New" networking API */
if (lsa->sa.sa_family == AF_INET) {
return lsa->sin.sin_port;
}
- return -1;
/* What? UNIX socket? IPX?? :) */
+ return -1;
}
void set_nport(len_and_sockaddr *lsa, unsigned port)
/* What? UNIX socket? IPX?? :) */
}
-/* peer: "1.2.3.4[:port]", "www.google.com[:port]"
+/* host: "1.2.3.4[:port]", "www.google.com[:port]"
* port: if neither of above specifies port #
*/
static len_and_sockaddr* str2sockaddr(const char *host, int port, int ai_flags)
int rc = getnameinfo(sa, salen,
host, sizeof(host),
serv, sizeof(serv),
- flags | NI_NUMERICSERV /* do not resolve port# */
+ /* do not resolve port# into service _name_ */
+ flags | NI_NUMERICSERV
);
- if (rc) return NULL;
-// We probably need to use [%s]:%s for IPv6...
- return xasprintf("%s:%s", host, serv);
+ if (rc)
+ return NULL;
+#if ENABLE_FEATURE_IPV6
+ if (sa->sa_family == AF_INET6)
+ return xasprintf("[%s]:%s", host, serv);
+#endif
+ /* For now we don't support anything else, so it has to be INET */
+ /*if (sa->sa_family == AF_INET)*/
+ return xasprintf("%s:%s", host, serv);
}
char* xmalloc_sockaddr2host(const struct sockaddr *sa, socklen_t salen)
* and we want to connect to only one IP... */
server->lsa = host2sockaddr(argv[0], bb_lookup_port(port, "tcp", 21));
if (verbose_flag) {
- printf("Connecting to %s [%s]\n", argv[0],
+ printf("Connecting to %s (%s)\n", argv[0],
xmalloc_sockaddr2dotted(&server->lsa->sa, server->lsa->len));
}
* and we want to connect to only one IP... */
lsa = host2sockaddr(server.host, server.port);
if (!(opt & WGET_OPT_QUIET)) {
- fprintf(stderr, "Connecting to %s [%s]\n", server.host,
+ fprintf(stderr, "Connecting to %s (%s)\n", server.host,
xmalloc_sockaddr2dotted(&lsa->sa, lsa->len));
- /* We leak xmalloc_sockaddr2dotted result */
+ /* We leak result of xmalloc_sockaddr2dotted */
}
if (use_proxy || !target.is_ftp) {