Skip to contentSkip to conversation

socket connected to itself with RH 2.2.14-5.0? (Problem with example from Stevens)

DISCUSSION Dan Kegel 1 participant 2 messages Aug 21, 2001 – Aug 23, 2001

lore
Share & tools
lore

Dan Kegel

author
#0 lore raw

I've been fooling around with porting
the example programs from Richard Stevens'
"Unix Network Programming, Volume 1, 2nd edition" to Linux. The patches I've come up with so far, along with instructions for reproducing my results, are available at http://www.kegel.com/unpv1/
My goal is to reproduce the results in table 27-1.

Along the way, I have been running both server and client on the same machine (it's easier to script that way for testing). Oddly, on Red Hat 6.2, the client often hangs within a minute or two. Poking around a bit shows that the client is blocked in read. OK so far, that could be a bug in the program or how I'm using it.

The interesting bit is that (after you wait long enough for other activity to finish up) all threads of the server are serenely sitting in accept(), knowing nothing about the client supposedly connected to it. Curiously, netstat -pant | grep 127.0.0.1 shows just

tcp 0 0 127.0.0.1:2003 127.0.0.1:2003 ESTABLISHED 965/client

Erm, could the client have connected to *itself* somehow?

Doesn't happen with Red Hat 7.1. I am now compiling vanilla 2.2.19 to see if that fixes it, too.

(I seem to have a knack for triggering this kind of thing. ucd-snmp/snmpget used to crash if you had it query itself :-)

- Dan

Signature · 1 line
"I have seen the future, and it licks itself clean." -- Bucky Katt
author
#1 lore raw
Quoted 8 lines · Ralf Baechle
Quoted 3 lines · Dan Kegel

tcp 0 0 127.0.0.1:2003 127.0.0.1:2003 ESTABLISHED 965/client

Erm, could the client have connected to *itself* somehow?

I would not consider that a bug even though certainly not very helpful. Now I wonder if this could potencially be abused for nice DoS attacks ...

After running the server on a port not in the ephemeral range, the problem goes away. It's just a funny thing that can happen when you're connecting to a server on your own box, so no big deal.
- Dan

Signature · 1 line
"I have seen the future, and it licks itself clean." -- Bucky Katt