From owner-freebsd-current@FreeBSD.ORG Mon Apr 9 22:15:49 2007 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 3D66516A400 for ; Mon, 9 Apr 2007 22:15:49 +0000 (UTC) (envelope-from coolaz@web.de) Received: from fmmailgate02.web.de (fmmailgate02.web.de [217.72.192.227]) by mx1.freebsd.org (Postfix) with ESMTP id C744C13C457 for ; Mon, 9 Apr 2007 22:15:48 +0000 (UTC) (envelope-from coolaz@web.de) Received: from smtp08.web.de (fmsmtp08.dlan.cinetic.de [172.20.5.216]) by fmmailgate02.web.de (Postfix) with ESMTP id 5AFFA720B2EB for ; Mon, 9 Apr 2007 23:44:24 +0200 (CEST) Received: from [91.16.214.226] (helo=example.net) by smtp08.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.107 #114) id 1Hb1ew-0007ev-00 for freebsd-current@freebsd.org; Mon, 09 Apr 2007 23:44:23 +0200 Received: by example.net (nbSMTP-1.00) for uid 1001 (using TLSv1/SSLv3 with cipher AES256-SHA (256/256 bits)) coolaz@web.de; Mon, 9 Apr 2007 23:45:05 +0200 (CEST) Date: Mon, 9 Apr 2007 23:45:04 +0200 From: Martin Kulas To: freebsd-current@freebsd.org Message-ID: <20070409214504.GA1780@thunderbird.tld> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="DocE+STaALJfprDB" Content-Disposition: inline User-Agent: Mutt/1.4.2.2i X-PGP-Key: http://www.stud.uni-hamburg.de/~kulas/mkulas_pubkey.asc Sender: coolaz@web.de X-Sender: coolaz@web.de X-Mailman-Approved-At: Mon, 09 Apr 2007 22:53:14 +0000 Subject: netcat with SCTP support X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Apr 2007 22:15:49 -0000 --DocE+STaALJfprDB Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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.=20 But there is a problem I could not solve: If I open an SCTP listening socke= t=20 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 --- 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 #endif +#include #include #include #include @@ -71,6 +72,7 @@ =20 /* 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 =3D NULL; =20 while ((ch =3D getopt(argc, argv, - "46e:DEdhi:jklnoP:p:rSs:tT:Uuvw:X:x:z")) !=3D -1) { + "c46e:DEdhi:jklnoP:p:rSs:tT:Uuvw:X:x:z")) !=3D -1) { switch (ch) { + case 'c': + cflag =3D 1; + break; case '4': family =3D AF_INET; break; @@ -257,6 +262,8 @@ if (argv[0] && !argv[1] && family =3D=3D AF_UNIX) { if (uflag) errx(1, "cannot use -u and -U"); + if (cflag) + errx(1, "cannot use -c and -U"); host =3D argv[0]; uport =3D NULL; } else if (argv[0] && !argv[1]) { @@ -283,13 +290,23 @@ if (family !=3D AF_UNIX) { memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family =3D family; - hints.ai_socktype =3D uflag ? SOCK_DGRAM : SOCK_STREAM; - hints.ai_protocol =3D uflag ? IPPROTO_UDP : IPPROTO_TCP; + if (cflag) { + hints.ai_socktype =3D SOCK_STREAM; + // XXX IPPROTO_SCTP not supported form getaddrinfo + } else { + hints.ai_socktype =3D uflag ? SOCK_DGRAM : SOCK_STREAM; + hints.ai_protocol =3D uflag ? IPPROTO_UDP : IPPROTO_TCP; + } if (nflag) hints.ai_flags |=3D AI_NUMERICHOST; } =20 + 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"); =20 @@ -418,7 +435,7 @@ } =20 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 @@ =20 res0 =3D res; do { - if ((s =3D socket(res0->ai_family, res0->ai_socktype, - res0->ai_protocol)) < 0) - continue; + if (cflag) { + if ((s =3D socket(res0->ai_family, res0->ai_socktype, + IPPROTO_SCTP)) < 0) + continue; + } else { + if ((s =3D socket(res0->ai_family, res0->ai_socktype, + res0->ai_protocol)) < 0) + continue; + } #ifdef IPSEC if (ipsec_policy[0] !=3D NULL) add_ipsec_policy(s, ipsec_policy[0]); @@ -532,7 +555,8 @@ memset(&ahints, 0, sizeof(struct addrinfo)); ahints.ai_family =3D res0->ai_family; ahints.ai_socktype =3D uflag ? SOCK_DGRAM : SOCK_STREAM; - ahints.ai_protocol =3D uflag ? IPPROTO_UDP : IPPROTO_TCP; + if (!cflag) + ahints.ai_protocol =3D uflag ? IPPROTO_UDP : IPPROTO_TCP; ahints.ai_flags =3D AI_PASSIVE; if ((error =3D 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") ); =20 close(s); s =3D -1; @@ -587,10 +611,15 @@ =20 res0 =3D res; do { - if ((s =3D socket(res0->ai_family, res0->ai_socktype, - res0->ai_protocol)) < 0) - continue; - + if (cflag) { + if ((s =3D socket(res0->ai_family, res0->ai_socktype, + IPPROTO_SCTP)) < 0) + continue; + } else { + if ((s =3D socket(res0->ai_family, res0->ai_socktype, + res0->ai_protocol)) < 0) + continue; + } ret =3D setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x)); if (ret =3D=3D -1) err(1, NULL); --=20 PGP Key: http://www.stud.uni-hamburg.de/~kulas/mkulas_pubkey.asc --DocE+STaALJfprDB Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (FreeBSD) iD8DBQFGGrPfu1jKg1agQ1oRAnRxAKCar+RgaK3RBM87hbEfy3/OtBF1vgCgs+Jy rCHJjOW9TRzACKhwslFdAak= =CwkG -----END PGP SIGNATURE----- --DocE+STaALJfprDB--