Bug 19302 - read("/proc/net/tcp") fails with buffer <= 128 bytes.
Summary: read("/proc/net/tcp") fails with buffer <= 128 bytes.
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: kernel   
(Show other bugs)
Version: 7.0
Hardware: i386
OS: Linux
Target Milestone: ---
Assignee: Arjan van de Ven
QA Contact: Brian Brock
Depends On:
TreeView+ depends on / blocked
Reported: 2000-10-18 03:13 UTC by Sam Varshavchik
Modified: 2007-04-18 16:29 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2002-12-16 04:08:44 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
An example (2.89 KB, text/plain)
2000-10-18 03:14 UTC, Sam Varshavchik
no flags Details

Description Sam Varshavchik 2000-10-18 03:13:54 UTC
Make sure the machine has at least a few dozen TCP sockets open:

dd if=/proc/net/tcp bs=129          -- shows all open TCP sockets

dd if=/proc/net/tcp bs=128          -- does not

I stumbled across this when I tried to run less on /proc/net/tcp, and got
far fewer sockets than I knew I had. After tracking down what was going on,
I discovered that if you keep doing a read on /proc/net/tcp with a buffer
size of 128 bytes or less, you're going to get a premature EOF indication.

Comment 1 Sam Varshavchik 2000-10-18 03:14:21 UTC
Created attachment 4309 [details]
An example

Comment 2 Arjan van de Ven 2000-10-18 17:27:34 UTC
This is an off-by-one error; the patch below fixes it for me.

--- linux/net/ipv4/proc.c.org   Wed Oct 18 18:27:26 2000
+++ linux/net/ipv4/proc.c       Wed Oct 18 19:27:58 2000
@@ -186,7 +186,7 @@
                                if (req->sk)
                                pos += 128;
-                               if (pos < offset)
+                               if (pos <= offset)
                                get__openreq(sp, req, tmpbuf, i);
                                len += sprintf(buffer+len, "%-127s\n", tmpbuf);
@@ -196,7 +196,7 @@

                pos += 128;
-               if (pos < offset)
+               if (pos <= offset)
                        goto next;

                get__sock(sp, tmpbuf, i, format);

Comment 3 Alan Cox 2002-12-16 04:08:44 UTC
Long fixed should have been closed

Note You need to log in before you can comment on or make changes to this bug.