summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenis Vlasenko2007-06-05 20:08:11 +0000
committerDenis Vlasenko2007-06-05 20:08:11 +0000
commit5c51a7ca52beb6958fda45f0de480f6ac1769ec6 (patch)
tree55bc26e011712115ecdfcb01588f9f65f6397462 /networking
parent6c501a71ae50fa8f788bbc46511e8c4071e5f897 (diff)
downloadbusybox-5c51a7ca52beb6958fda45f0de480f6ac1769ec6.zip
busybox-5c51a7ca52beb6958fda45f0de480f6ac1769ec6.tar.gz
nc: make connecting to IPv4 from IPv6-enabled hosts easier
(was requiring -s <local addr>)
Diffstat (limited to 'networking')
-rw-r--r--networking/nc_bloaty.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c
index 5096e32..a318c81 100644
--- a/networking/nc_bloaty.c
+++ b/networking/nc_bloaty.c
@@ -751,6 +751,13 @@ int nc_main(int argc, char **argv)
/* We manage our fd's so that they are never 0,1,2 */
/*bb_sanitize_stdio(); - not needed */
+ if (argv[0]) {
+ themaddr = xhost2sockaddr(argv[0],
+ argv[1]
+ ? bb_lookup_port(argv[1], o_udpmode ? "udp" : "tcp", 0)
+ : 0);
+ }
+
/* create & bind network socket */
x = (o_udpmode ? SOCK_DGRAM : SOCK_STREAM);
if (option_mask32 & OPT_s) { /* local address */
@@ -758,7 +765,11 @@ int nc_main(int argc, char **argv)
ouraddr = xhost2sockaddr(str_s, o_lport);
x = xsocket(ouraddr->sa.sa_family, x, 0);
} else {
- x = xsocket_type(&ouraddr, x);
+ /* We try IPv6, then IPv4, unless addr family is
+ * implicitly set by way of remote addr/port spec */
+ x = xsocket_type(&ouraddr,
+ USE_FEATURE_IPV6((themaddr ? themaddr->sa.sa_family : AF_UNSPEC),)
+ x);
if (o_lport)
set_nport(ouraddr, htons(o_lport));
}
@@ -789,14 +800,6 @@ int nc_main(int argc, char **argv)
xmove_fd(xopen(str_o, O_WRONLY|O_CREAT|O_TRUNC), ofd);
#endif
- if (argv[0]) {
- themaddr = xhost2sockaddr(argv[0],
- argv[1]
- ? bb_lookup_port(argv[1], o_udpmode ? "udp" : "tcp", 0)
- : 0);
-///what if sa_family won't match??
- }
-
if (o_listen) {
dolisten();
/* dolisten does its own connect reporting */