diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-25 13:16:53 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-25 13:16:53 +0000 |
commit | f6b4685691ebe00f28e4f9148a1a255e87b8d312 (patch) | |
tree | f9445de4ac97a635d2fc8a9deeb29a892a0e81ba /networking/nc.c | |
parent | 9ac3dc764a78b51fe8fdcd1b4682850de098733b (diff) | |
download | busybox-w32-f6b4685691ebe00f28e4f9148a1a255e87b8d312.tar.gz busybox-w32-f6b4685691ebe00f28e4f9148a1a255e87b8d312.tar.bz2 busybox-w32-f6b4685691ebe00f28e4f9148a1a255e87b8d312.zip |
add FEATURE_UNIX_LOCAL. By Ingo van Lil (inguin AT gmx.de)
Diffstat (limited to 'networking/nc.c')
-rw-r--r-- | networking/nc.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/networking/nc.c b/networking/nc.c index e64c998bc..9c3f116d2 100644 --- a/networking/nc.c +++ b/networking/nc.c | |||
@@ -34,7 +34,6 @@ int nc_main(int argc, char **argv) | |||
34 | IF_NOT_NC_EXTRA (const) unsigned delay = 0; | 34 | IF_NOT_NC_EXTRA (const) unsigned delay = 0; |
35 | IF_NOT_NC_EXTRA (const int execparam = 0;) | 35 | IF_NOT_NC_EXTRA (const int execparam = 0;) |
36 | IF_NC_EXTRA (char **execparam = NULL;) | 36 | IF_NC_EXTRA (char **execparam = NULL;) |
37 | len_and_sockaddr *lsa; | ||
38 | fd_set readfds, testfds; | 37 | fd_set readfds, testfds; |
39 | int opt; /* must be signed (getopt returns -1) */ | 38 | int opt; /* must be signed (getopt returns -1) */ |
40 | 39 | ||
@@ -44,17 +43,17 @@ int nc_main(int argc, char **argv) | |||
44 | while ((opt = getopt(argc, argv, | 43 | while ((opt = getopt(argc, argv, |
45 | "" IF_NC_SERVER("lp:") IF_NC_EXTRA("w:i:f:e:") )) > 0 | 44 | "" IF_NC_SERVER("lp:") IF_NC_EXTRA("w:i:f:e:") )) > 0 |
46 | ) { | 45 | ) { |
47 | if (ENABLE_NC_SERVER && opt=='l') | 46 | if (ENABLE_NC_SERVER && opt == 'l') |
48 | IF_NC_SERVER(do_listen++); | 47 | IF_NC_SERVER(do_listen++); |
49 | else if (ENABLE_NC_SERVER && opt=='p') | 48 | else if (ENABLE_NC_SERVER && opt == 'p') |
50 | IF_NC_SERVER(lport = bb_lookup_port(optarg, "tcp", 0)); | 49 | IF_NC_SERVER(lport = bb_lookup_port(optarg, "tcp", 0)); |
51 | else if (ENABLE_NC_EXTRA && opt=='w') | 50 | else if (ENABLE_NC_EXTRA && opt == 'w') |
52 | IF_NC_EXTRA( wsecs = xatou(optarg)); | 51 | IF_NC_EXTRA( wsecs = xatou(optarg)); |
53 | else if (ENABLE_NC_EXTRA && opt=='i') | 52 | else if (ENABLE_NC_EXTRA && opt == 'i') |
54 | IF_NC_EXTRA( delay = xatou(optarg)); | 53 | IF_NC_EXTRA( delay = xatou(optarg)); |
55 | else if (ENABLE_NC_EXTRA && opt=='f') | 54 | else if (ENABLE_NC_EXTRA && opt == 'f') |
56 | IF_NC_EXTRA( cfd = xopen(optarg, O_RDWR)); | 55 | IF_NC_EXTRA( cfd = xopen(optarg, O_RDWR)); |
57 | else if (ENABLE_NC_EXTRA && opt=='e' && optind <= argc) { | 56 | else if (ENABLE_NC_EXTRA && opt == 'e' && optind <= argc) { |
58 | /* We cannot just 'break'. We should let getopt finish. | 57 | /* We cannot just 'break'. We should let getopt finish. |
59 | ** Or else we won't be able to find where | 58 | ** Or else we won't be able to find where |
60 | ** 'host' and 'port' params are | 59 | ** 'host' and 'port' params are |
@@ -80,9 +79,12 @@ int nc_main(int argc, char **argv) | |||
80 | argc -= optind; | 79 | argc -= optind; |
81 | // -l and -f don't mix | 80 | // -l and -f don't mix |
82 | if (do_listen && cfd) bb_show_usage(); | 81 | if (do_listen && cfd) bb_show_usage(); |
83 | // Listen or file modes need zero arguments, client mode needs 2 | 82 | // File mode needs need zero arguments, listen mode needs zero or one, |
84 | if (do_listen || cfd) { | 83 | // client mode needs one or two |
84 | if (cfd) { | ||
85 | if (argc) bb_show_usage(); | 85 | if (argc) bb_show_usage(); |
86 | } else if (do_listen) { | ||
87 | if (argc > 1) bb_show_usage(); | ||
86 | } else { | 88 | } else { |
87 | if (!argc || argc > 2) bb_show_usage(); | 89 | if (!argc || argc > 2) bb_show_usage(); |
88 | } | 90 | } |
@@ -99,24 +101,20 @@ int nc_main(int argc, char **argv) | |||
99 | 101 | ||
100 | if (!cfd) { | 102 | if (!cfd) { |
101 | if (do_listen) { | 103 | if (do_listen) { |
102 | /* create_and_bind_stream_or_die(NULL, lport) | 104 | sfd = create_and_bind_stream_or_die(argv[0], lport); |
103 | * would've work wonderfully, but we need | ||
104 | * to know lsa */ | ||
105 | sfd = xsocket_stream(&lsa); | ||
106 | if (lport) | ||
107 | set_nport(lsa, htons(lport)); | ||
108 | setsockopt_reuseaddr(sfd); | ||
109 | xbind(sfd, &lsa->u.sa, lsa->len); | ||
110 | xlisten(sfd, do_listen); /* can be > 1 */ | 105 | xlisten(sfd, do_listen); /* can be > 1 */ |
106 | #if 0 /* nc-1.10 does not do this (without -v) */ | ||
111 | /* If we didn't specify a port number, | 107 | /* If we didn't specify a port number, |
112 | * query and print it after listen() */ | 108 | * query and print it after listen() */ |
113 | if (!lport) { | 109 | if (!lport) { |
114 | getsockname(sfd, &lsa->u.sa, &lsa->len); | 110 | len_and_sockaddr lsa; |
115 | lport = get_nport(&lsa->u.sa); | 111 | lsa.len = LSA_SIZEOF_SA; |
112 | getsockname(sfd, &lsa.u.sa, &lsa.len); | ||
113 | lport = get_nport(&lsa.u.sa); | ||
116 | fdprintf(2, "%d\n", ntohs(lport)); | 114 | fdprintf(2, "%d\n", ntohs(lport)); |
117 | } | 115 | } |
116 | #endif | ||
118 | close_on_exec_on(sfd); | 117 | close_on_exec_on(sfd); |
119 | free(lsa); | ||
120 | accept_again: | 118 | accept_again: |
121 | cfd = accept(sfd, NULL, 0); | 119 | cfd = accept(sfd, NULL, 0); |
122 | if (cfd < 0) | 120 | if (cfd < 0) |