netcat (openbsd) has no listening support?

This forum is for discussion about general software issues.

netcat (openbsd) has no listening support?

Postby normaldotcom » Tue Aug 12, 2014 2:33 pm

The ALARM build of openbsd-netcat doesn't seem to work in listening mode for me...

$this->bbcode_second_pass_code('', '
host ~ # netcat -l 9000
netcat: Protocol not available
')

However piping data to a serving netcat works just fine:

$this->bbcode_second_pass_code('', 'echo teststring | nc 10.10.10.10 9000')

On a non-ARM Arch Linux system, openbsd-netcat listens as expected. Is support for listening just not compiled into the ALARM build?

Thanks!
normaldotcom
 
Posts: 3
Joined: Thu Dec 05, 2013 4:35 pm

Re: netcat (openbsd) has no listening support?

Postby aquassaut » Fri Sep 26, 2014 9:07 pm

I have the same issue and it's been bugging me for some time too.
It is apparently a problem with the socket option SO_REUSEPORT not working on our systems.
A quick fix is to recompile netcat with this modified PKGBUILD :

$this->bbcode_second_pass_code('', '# $Id: PKGBUILD 114115 2014-07-01 13:31:47Z spupykin $
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Andrej Gelenberg <andrej.gelenberg@udo.edu>

pkgname="openbsd-netcat"
pkgver=1.105_7
pkgrel=7
pkgdesc="TCP/IP swiss army knife. OpenBSD variant."
arch=('i686' 'x86_64')
url="http://packages.debian.org/sid/netcat-openbsd"
license=('BSD')
depends=('libbsd')
makedepends=('gcc' 'make')
provides=('netcat')
conflicts=('gnu-netcat')
source=("http://ftp.debian.org/debian/pool/main/n/netcat-openbsd/netcat-openbsd_${pkgver%_*}.orig.tar.gz"
"http://ftp.debian.org/debian/pool/main/n/netcat-openbsd/netcat-openbsd_${pkgver/_/-}.debian.tar.gz")
md5sums=('7e67b22f1ad41a1b7effbb59ff28fca1'
'e914f8eb7eda5c75c679dd77787ac76b')

build() {
cd $srcdir/netcat-openbsd-${pkgver%_*}
for i in `cat ../debian/patches/series`; do
echo "** patch $i" 1>&2
cat "../debian/patches/$i"
done | patch -p1
sed -i 's/defined(SO_REUSEPORT)/0/g' netcat.c

make \
CFLAGS="$CFLAGS -DDEBIAN_VERSION=\"\\\"${pkgrel}\\\"\" -I/usr/include/libbsd" \
LDFLAGS="$LDFLAGS -lbsd"
}

package() {
cd $srcdir/netcat-openbsd-${pkgver%_*}
install -Dm0755 nc $pkgdir/usr/bin/nc
ln -s nc $pkgdir/usr/bin/netcat
install -Dm0644 nc.1 $pkgdir/usr/share/man/man1/nc.1
install -dm0755 $pkgdir/usr/share/licenses/$pkgname/
head -n28 netcat.c | tail -n+2 >$pkgdir/usr/share/licenses/$pkgname/LICENSE
}')
aquassaut
 
Posts: 2
Joined: Fri Sep 26, 2014 8:33 pm

Re: netcat (openbsd) has no listening support?

Postby WarheadsSE » Fri Sep 26, 2014 9:14 pm

What was the modification? Why not issue a PR for this?
Core Developer
Remember: Arch Linux ARM is entirely community donation supported!
WarheadsSE
Developer
 
Posts: 6807
Joined: Mon Oct 18, 2010 2:12 pm

Re: netcat (openbsd) has no listening support?

Postby aquassaut » Fri Sep 26, 2014 9:26 pm

It's the sed line. It turns
$this->bbcode_second_pass_code('', '
#if defined(SO_REUSEPORT)
setsockopt(..., SO_REUSEPORT, ...);
#endif
')

into

$this->bbcode_second_pass_code('', '
#if 0
...
')

which prevents netcat to add the SO_REUSEPORT option to the socket.

No PR because I don't know what the root of the problem is. The thing is, the SO_REUSEPORT option is actually useful, turning it off for everybody is probably a bad idea, especially since I don't know if it is supported by all other boards targeted by the ALARM effort. Also, on my board/kernel (beaglebone black/3.8.13-35-ARCH) the SO_REUSEPORT opt is defined in /usr/include/asm-generic/socket.h . I don't think it should be defined there to begin with, since it doesn't seem to be supported, so patching it in netcat is probably not a good long term solution.


Edit : I got a little more info.

So SO_REUSEPORT was introduced in the kernel at 3.9 (link to the changelog). My kernel is 3.8., so I don't have it, but for some inexplicable reason, my core/linux-api-headers is version 3.16.2-1, and hence includes the SO_REUSEPORT definition in /usr/include/asm/socket.h . Really, the problem wasn't with netcat, but with a mismatch between my kernel version and my linux-api-headers version.

So to sum it up :
    * People using the binary openbsd-netcat from pacman and running the core/linux-am33x-legacy kernel (or any kernel < 3.9) will have the problem. They can try and recompile their binary with the repo PKGBUILD.
    * People running a kernel version < 3.9 and linux-api-headers > 3.9 will compile a wrong binary from the repo PKGBUILD. They can recompile their binary with my modified PKGBUILD (or just switch to gnu-netcat, which doesn't support SO_REUSEPORT at all).
    * Everybody else should be fine.
aquassaut
 
Posts: 2
Joined: Fri Sep 26, 2014 8:33 pm


Return to General

Who is online

Users browsing this forum: No registered users and 8 guests