netcat with SCTP support
Randall Stewart
rrs at cisco.com
Tue Apr 10 10:36:19 UTC 2007
Martin:
Thanks for checking out SCTP for netcat... let me
see if I can re-create this bug with current and figure
out what is broken... This sounds like a bug with the
TCP model..
I will be a bit slow.. I am on vacation this week and for
some crazy reason my wife thinks I should be working on
putting in a yard instead of working on the computer :-)
I can work only limited times in the AM when everyone
is still asleep :-0
So to recreate this.. I set things up run it
and ctl-c the client?
R
Martin Kulas wrote:
> Hello!
>
> I am running -CURRENT and I am happy to have SCTP support. I wrote a patch
> for netcat so I can experiment with SCTP. The patch opens a SCTP socket
> in one-to-one style.
> But there is a problem I could not solve: If I open an SCTP listening socket
> with netcat and connect to it with netcat, data transfer works correctly. When I
> kill the client process, the server process does not react on the
> SHUTDOWN-chunk sent to it: poll() does not notify the process that the
> association has been closed. Using TCP poll() works correctly.
> Does anyone know how to solve this problem?
>
> Thanks in advance,
> Martin
>
> <patch>
> --- netcat.c.orig Fri Mar 30 21:58:02 2007
> +++ netcat.c Mon Apr 9 16:59:21 2007
> @@ -44,6 +44,7 @@
> #ifdef IPSEC
> #include <netinet6/ipsec.h>
> #endif
> +#include <netinet/sctp.h>
> #include <netinet/tcp.h>
> #include <netinet/ip.h>
> #include <arpa/telnet.h>
> @@ -71,6 +72,7 @@
>
> /* Command Line Options */
> int Eflag; /* Use IPsec ESP */
> +int cflag; /* Use SCTP */
> int dflag; /* detached, no stdin */
> unsigned int iflag; /* Interval Flag */
> int jflag; /* use jumbo frames if we can */
> @@ -138,8 +140,11 @@
> sv = NULL;
>
> while ((ch = getopt(argc, argv,
> - "46e:DEdhi:jklnoP:p:rSs:tT:Uuvw:X:x:z")) != -1) {
> + "c46e:DEdhi:jklnoP:p:rSs:tT:Uuvw:X:x:z")) != -1) {
> switch (ch) {
> + case 'c':
> + cflag = 1;
> + break;
> case '4':
> family = AF_INET;
> break;
> @@ -257,6 +262,8 @@
> if (argv[0] && !argv[1] && family == AF_UNIX) {
> if (uflag)
> errx(1, "cannot use -u and -U");
> + if (cflag)
> + errx(1, "cannot use -c and -U");
> host = argv[0];
> uport = NULL;
> } else if (argv[0] && !argv[1]) {
> @@ -283,13 +290,23 @@
> if (family != AF_UNIX) {
> memset(&hints, 0, sizeof(struct addrinfo));
> hints.ai_family = family;
> - hints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
> - hints.ai_protocol = uflag ? IPPROTO_UDP : IPPROTO_TCP;
> + if (cflag) {
> + hints.ai_socktype = SOCK_STREAM;
> + // XXX IPPROTO_SCTP not supported form getaddrinfo
> + } else {
> + hints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
> + hints.ai_protocol = uflag ? IPPROTO_UDP : IPPROTO_TCP;
> + }
> if (nflag)
> hints.ai_flags |= AI_NUMERICHOST;
> }
>
> + if ( cflag && uflag )
> + errx(1, "cannot use -c and -u");
> +
> if (xflag) {
> + if (cflag)
> + errx(1, "no proxy support for SCTP mode");
> if (uflag)
> errx(1, "no proxy support for UDP mode");
>
> @@ -418,7 +435,7 @@
> }
>
> printf("Connection to %s %s port [%s/%s] succeeded!\n",
> - host, portlist[i], uflag ? "udp" : "tcp",
> + host, portlist[i], uflag ? "udp" : (cflag ? "sctp" : "tcp"),
> sv ? sv->s_name : "*");
> }
> if (!zflag)
> @@ -515,9 +532,15 @@
>
> res0 = res;
> do {
> - if ((s = socket(res0->ai_family, res0->ai_socktype,
> - res0->ai_protocol)) < 0)
> - continue;
> + if (cflag) {
> + if ((s = socket(res0->ai_family, res0->ai_socktype,
> + IPPROTO_SCTP)) < 0)
> + continue;
> + } else {
> + if ((s = socket(res0->ai_family, res0->ai_socktype,
> + res0->ai_protocol)) < 0)
> + continue;
> + }
> #ifdef IPSEC
> if (ipsec_policy[0] != NULL)
> add_ipsec_policy(s, ipsec_policy[0]);
> @@ -532,7 +555,8 @@
> memset(&ahints, 0, sizeof(struct addrinfo));
> ahints.ai_family = res0->ai_family;
> ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
> - ahints.ai_protocol = uflag ? IPPROTO_UDP : IPPROTO_TCP;
> + if (!cflag)
> + ahints.ai_protocol = uflag ? IPPROTO_UDP : IPPROTO_TCP;
> ahints.ai_flags = AI_PASSIVE;
> if ((error = getaddrinfo(sflag, pflag, &ahints, &ares)))
> errx(1, "getaddrinfo: %s", gai_strerror(error));
> @@ -549,7 +573,7 @@
> break;
> else if (vflag)
> warn("connect to %s port %s (%s) failed", host, port,
> - uflag ? "udp" : "tcp");
> + uflag ? "udp" : (cflag ? "sctp" : "tcp") );
>
> close(s);
> s = -1;
> @@ -587,10 +611,15 @@
>
> res0 = res;
> do {
> - if ((s = socket(res0->ai_family, res0->ai_socktype,
> - res0->ai_protocol)) < 0)
> - continue;
> -
> + if (cflag) {
> + if ((s = socket(res0->ai_family, res0->ai_socktype,
> + IPPROTO_SCTP)) < 0)
> + continue;
> + } else {
> + if ((s = socket(res0->ai_family, res0->ai_socktype,
> + res0->ai_protocol)) < 0)
> + continue;
> + }
> ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
> if (ret == -1)
> err(1, NULL);
> </patch>
--
Randall Stewart
NSSTG - Cisco Systems Inc.
803-345-0369 <or> 803-317-4952 (cell)
More information about the freebsd-current
mailing list