diff --git a/ncat/ncat_connect.c b/ncat/ncat_connect.c index ccecb00e0..1277ba278 100644 --- a/ncat/ncat_connect.c +++ b/ncat/ncat_connect.c @@ -523,7 +523,7 @@ int ncat_connect(void) #if HAVE_SYS_UN_H /* For DGRAM UNIX socket we have to use source socket */ - if (o.af == AF_UNIX && o.udp) + if (o.af == AF_UNIX && o.proto == IPPROTO_UDP) { if (srcaddr.storage.ss_family != AF_UNIX) { char *tmp_name = NULL; @@ -559,7 +559,7 @@ int ncat_connect(void) #if HAVE_SYS_UN_H if (o.af == AF_UNIX) { - if (o.udp) { + if (o.proto == IPPROTO_UDP) { nsock_connect_unixsock_datagram(mypool, cs.sock_nsi, connect_handler, NULL, &targetss.sockaddr, SUN_LEN((struct sockaddr_un *)&targetss.sockaddr)); @@ -570,13 +570,13 @@ int ncat_connect(void) } } else #endif - if (o.udp) { + if (o.proto == IPPROTO_UDP) { nsock_connect_udp(mypool, cs.sock_nsi, connect_handler, NULL, &targetss.sockaddr, targetsslen, inet_port(&targetss)); } #ifdef HAVE_OPENSSL - else if (o.sctp && o.ssl) { + else if (o.proto == IPPROTO_SCTP && o.ssl) { nsock_connect_ssl(mypool, cs.sock_nsi, connect_handler, o.conntimeout, NULL, &targetss.sockaddr, targetsslen, @@ -584,7 +584,7 @@ int ncat_connect(void) NULL); } #endif - else if (o.sctp) { + else if (o.proto == IPPROTO_SCTP) { nsock_connect_sctp(mypool, cs.sock_nsi, connect_handler, o.conntimeout, NULL, &targetss.sockaddr, targetsslen, @@ -692,7 +692,7 @@ int ncat_connect(void) } #if HAVE_SYS_UN_H - if (o.af == AF_UNIX && o.udp) { + if (o.af == AF_UNIX && o.proto == IPPROTO_UDP) { if (o.verbose) loguser("Deleting source DGRAM Unix domain socket. [%s]\n", srcaddr.un.sun_path); unlink(srcaddr.un.sun_path); diff --git a/ncat/ncat_core.c b/ncat/ncat_core.c index 6da1bbc57..c4d314388 100644 --- a/ncat/ncat_core.c +++ b/ncat/ncat_core.c @@ -134,14 +134,13 @@ void options_init(void) o.debug = 0; o.target = NULL; o.af = AF_UNSPEC; + o.proto = IPPROTO_TCP; o.broker = 0; o.listen = 0; o.keepopen = 0; o.sendonly = 0; o.recvonly = 0; o.telnet = 0; - o.udp = 0; - o.sctp = 0; o.linedelay = 0; o.chat = 0; o.nodns = 0; diff --git a/ncat/ncat_core.h b/ncat/ncat_core.h index 82053eefd..96977818d 100644 --- a/ncat/ncat_core.h +++ b/ncat/ncat_core.h @@ -117,14 +117,14 @@ struct options { int debug; char *target; int af; + /* IPPROTO_TCP, IPPROTO_SCTP, or IPPROTO_UDP */ + int proto; int broker; int listen; int keepopen; int sendonly; int recvonly; int telnet; - int udp; - int sctp; int linedelay; int chat; int nodns; diff --git a/ncat/ncat_listen.c b/ncat/ncat_listen.c index 3a4a0acee..1631e44ac 100644 --- a/ncat/ncat_listen.c +++ b/ncat/ncat_listen.c @@ -807,7 +807,7 @@ int ncat_listen() { #if HAVE_SYS_UN_H if (o.af == AF_UNIX) - if (o.udp) + if (o.proto == IPPROTO_UDP) return ncat_listen_dgram(0); else return ncat_listen_stream(0); @@ -815,12 +815,14 @@ int ncat_listen() #endif if (o.httpserver) return ncat_http_server(); - else if (o.udp) - return ncat_listen_dgram(IPPROTO_UDP); - else if (o.sctp) - return ncat_listen_stream(IPPROTO_SCTP); + else if (o.proto == IPPROTO_UDP) + return ncat_listen_dgram(o.proto); + else if (o.proto == IPPROTO_SCTP) + return ncat_listen_stream(o.proto); + else if (o.proto == IPPROTO_TCP) + return ncat_listen_stream(o.proto); else - return ncat_listen_stream(IPPROTO_TCP); + bye("Unknown o.proto %d\n", o.proto); /* unreached */ return 1; diff --git a/ncat/ncat_main.c b/ncat/ncat_main.c index 6b202536a..59b80124a 100644 --- a/ncat/ncat_main.c +++ b/ncat/ncat_main.c @@ -258,7 +258,7 @@ int main(int argc, char *argv[]) {"allowfile", required_argument, NULL, 0}, {"telnet", no_argument, NULL, 't'}, {"udp", no_argument, NULL, 'u'}, - {"sctp", no_argument, &o.sctp, 1}, + {"sctp", no_argument, NULL, 0}, {"version", no_argument, NULL, 0}, {"verbose", no_argument, NULL, 'v'}, {"wait", required_argument, NULL, 'w'}, @@ -382,7 +382,7 @@ int main(int argc, char *argv[]) o.listen = 1; break; case 'u': - o.udp = 1; + o.proto = IPPROTO_UDP; break; case 'v': /* One -v activites verbose, after that it's debugging. */ @@ -446,6 +446,8 @@ int main(int argc, char *argv[]) host_list_add_filename(&deny_host_list, optarg); } else if (strcmp(long_options[option_index].name, "append-output") == 0) { o.append = 1; + } else if (strcmp(long_options[option_index].name, "sctp") == 0) { + o.proto = IPPROTO_SCTP; } #ifdef HAVE_OPENSSL else if (strcmp(long_options[option_index].name, "ssl-cert") == 0) { @@ -621,7 +623,7 @@ int main(int argc, char *argv[]) /* if using UNIX sockets just copy the path. * If it's not valid, it will fail later! */ if (o.af == AF_UNIX) { - if (o.udp) { + if (o.proto == IPPROTO_UDP) { srcaddr.un.sun_family = AF_UNIX; strncpy(srcaddr.un.sun_path, source, sizeof(srcaddr.un.sun_path)); srcaddrlen = SUN_LEN(&srcaddr.un); @@ -760,7 +762,7 @@ int main(int argc, char *argv[]) socksconnect = tmp; } - if (o.udp) { + if (o.proto == IPPROTO_UDP) { /* Don't allow a false sense of security if someone tries SSL over UDP. */ if (o.ssl) bye("UDP mode does not support SSL.");