Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ncat "bad file descriptor" error upon client connection

Tags:

tcp

netcat

Problem

I have been trying to use Ncat to view some TCP traffic on a CentOS virtual box. However, on this particular machine I can't even establish a simple server/client communication.

I open a TCP socket as a "server" or listener (forgive me if I'm mistaken on the correct terminology"

Terminal 1:

$ ncat -l 12345

Then, in a separate terminal I initiate the client connection and attempt to send a random string:

Terminal 2:

$ ncat my_hostname 13245
 <Random string to send>

This initiates the following error from my TCP "server"

Terminal 1:

close: Bad file descriptor

Terminal 2:

Ncat: Broken pipe.

I've run this exact sequence of commands via cygwin and they work fine. I'm not sure what could be causing this (unless it's the lack of root permissions? see below). Looking for something to debug. If it is root permissions or could be how can I verify that without having root permissions?

Extra (Relevant?) Information

I have run

$ Ncat my_hostname <port that I know has a TCP connection>

and it has output a lot of gibberish. Meanwhile, when I attempt to listen to the same port with tcpflow it tells me I don't have permission. So, is this perhaps just a permissions issue that Ncat isn't explicitly telling me about? I don't have root permissions on this machine so I can't test that hypothesis

like image 883
Bryce Avatar asked May 23 '18 17:05

Bryce


1 Answers

I had the same issue. I solved the problem by specifing the protocol family version.

nc -4  // using ipv4

you can try it

like image 69
LandyLiu Avatar answered Nov 08 '22 01:11

LandyLiu