diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-05 20:08:11 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-05 20:08:11 +0000 |
commit | 5c51a7ca52beb6958fda45f0de480f6ac1769ec6 (patch) | |
tree | 55bc26e011712115ecdfcb01588f9f65f6397462 /networking/nc_bloaty.c | |
parent | 6c501a71ae50fa8f788bbc46511e8c4071e5f897 (diff) | |
download | busybox-w32-5c51a7ca52beb6958fda45f0de480f6ac1769ec6.tar.gz busybox-w32-5c51a7ca52beb6958fda45f0de480f6ac1769ec6.tar.bz2 busybox-w32-5c51a7ca52beb6958fda45f0de480f6ac1769ec6.zip |
nc: make connecting to IPv4 from IPv6-enabled hosts easier
(was requiring -s <local addr>)
Diffstat (limited to 'networking/nc_bloaty.c')
-rw-r--r-- | networking/nc_bloaty.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c index 5096e3227..a318c8126 100644 --- a/networking/nc_bloaty.c +++ b/networking/nc_bloaty.c | |||
@@ -751,6 +751,13 @@ int nc_main(int argc, char **argv) | |||
751 | /* We manage our fd's so that they are never 0,1,2 */ | 751 | /* We manage our fd's so that they are never 0,1,2 */ |
752 | /*bb_sanitize_stdio(); - not needed */ | 752 | /*bb_sanitize_stdio(); - not needed */ |
753 | 753 | ||
754 | if (argv[0]) { | ||
755 | themaddr = xhost2sockaddr(argv[0], | ||
756 | argv[1] | ||
757 | ? bb_lookup_port(argv[1], o_udpmode ? "udp" : "tcp", 0) | ||
758 | : 0); | ||
759 | } | ||
760 | |||
754 | /* create & bind network socket */ | 761 | /* create & bind network socket */ |
755 | x = (o_udpmode ? SOCK_DGRAM : SOCK_STREAM); | 762 | x = (o_udpmode ? SOCK_DGRAM : SOCK_STREAM); |
756 | if (option_mask32 & OPT_s) { /* local address */ | 763 | if (option_mask32 & OPT_s) { /* local address */ |
@@ -758,7 +765,11 @@ int nc_main(int argc, char **argv) | |||
758 | ouraddr = xhost2sockaddr(str_s, o_lport); | 765 | ouraddr = xhost2sockaddr(str_s, o_lport); |
759 | x = xsocket(ouraddr->sa.sa_family, x, 0); | 766 | x = xsocket(ouraddr->sa.sa_family, x, 0); |
760 | } else { | 767 | } else { |
761 | x = xsocket_type(&ouraddr, x); | 768 | /* We try IPv6, then IPv4, unless addr family is |
769 | * implicitly set by way of remote addr/port spec */ | ||
770 | x = xsocket_type(&ouraddr, | ||
771 | USE_FEATURE_IPV6((themaddr ? themaddr->sa.sa_family : AF_UNSPEC),) | ||
772 | x); | ||
762 | if (o_lport) | 773 | if (o_lport) |
763 | set_nport(ouraddr, htons(o_lport)); | 774 | set_nport(ouraddr, htons(o_lport)); |
764 | } | 775 | } |
@@ -789,14 +800,6 @@ int nc_main(int argc, char **argv) | |||
789 | xmove_fd(xopen(str_o, O_WRONLY|O_CREAT|O_TRUNC), ofd); | 800 | xmove_fd(xopen(str_o, O_WRONLY|O_CREAT|O_TRUNC), ofd); |
790 | #endif | 801 | #endif |
791 | 802 | ||
792 | if (argv[0]) { | ||
793 | themaddr = xhost2sockaddr(argv[0], | ||
794 | argv[1] | ||
795 | ? bb_lookup_port(argv[1], o_udpmode ? "udp" : "tcp", 0) | ||
796 | : 0); | ||
797 | ///what if sa_family won't match?? | ||
798 | } | ||
799 | |||
800 | if (o_listen) { | 803 | if (o_listen) { |
801 | dolisten(); | 804 | dolisten(); |
802 | /* dolisten does its own connect reporting */ | 805 | /* dolisten does its own connect reporting */ |