Hi, the new --numeric-ports option makes netstat act as if the --numeric-hosts has been passed. That is, just like -n. ~$ netstat -Ainet --numeric-hosts tcp 0 0 10.75.100.76:4411 10.175.254.9:ssh ES... ~$ netstat -Ainet --numeric-ports tcp 0 0 10.75.100.76:4411 10.175.254.9:22 ES... and the man pages says :
Hi,
I'm amazed nobody replied to this bug for 3.5 years already!
I discovered myself the problem and I could get a behaviour closer
to the expectations by applying those changes:
--- inet.c.orig 2006-12-28 19:00:45.000000000 +0100
+++ inet.c 2006-12-28 18:57:37.000000000 +0100
@@ -159,16 +159,11 @@
#ifdef DEBUG
fprintf (stderr, "rresolve: %08lx, mask %08x, num %08x \n", ad, netmask, numeric);
#endif
- if (ad == INADDR_ANY) {
- if ((numeric & 0x0FFF) == 0) {
- if (numeric & 0x8000)
- safe_strncpy(name, "default", len);
- else
- safe_strncpy(name, "*", len);
- return (0);
- }
+ if (ad == INADDR_ANY && ! (numeric & 0x0004)) {
+ safe_strncpy(name, "*", len);
+ return (0);
}
- if (numeric & 0x0FFF) {
+ if (numeric & 0x0004) {
safe_strncpy(name, inet_ntoa(sin->sin_addr), len);
return (0);
}
At least when calling netstat --numeric-ports we now get
tcp 0 0 my.machine.com:139 *:* LISTEN
and netstat --numeric-hosts:
tcp 0 0 127.0.0.1:imap2 0.0.0.0:* LISTEN
But
- I don't know what is the supposed usage of "default" vs "*" for anycasts
- When I see how wrong the interpretation of the "numeric" flags
is in this part of the code I'm wondering for the whole stuff...
Phil
I think no matter what flags are given, the remote address of a LISTENING socket should be *:*. (at least if ad == INADDR_ANY, however I guess there are no other cases) Gruss Bernd
Bernd Eckenfels wrote: Maybe, but in the fct we don't know in which case we are (listening or not? local or remote addr?) so we've to choose 0.0.0.0 or * (or default) for all INADDR_ANY or make a lot of changes in the code just for cosmetics... Personally I'm fine with * in any cases but today netstat -ln gives 0.0.0.0:* so if you want to fix the --numeric-ports option while keeping the current behaviour of -l and -ln it's better to keep my initial proposal. Just my 2 cents. Phil
Hi, The following is a cut-down version of Philippe Teuwen's patch. I have taken out the changes he made to the special handling of INADDR_ANY, and just corrected the mask for reading the numeric parameter. The presence of FLAG_NUM_PORT or FLAG_NUM_USER should certainly be ignored in INET_rresolve(), shouldn't it? Hopefully you will be able to apply this patch. This is a very simple bug, but it has still managed to stay around for more than five years :-(.--- lib/inet.c.orig 2008-08-02 13:07:24.000000000 +0100 +++ lib/inet.c 2008-08-02 14:28:37.000000000 +0100 @@ -161,5 +161,5 @@ #endif if (ad == INADDR_ANY) { - if ((numeric & 0x0FFF) == 0) { + if (( numeric & FLAG_NUM_HOST ) == 0) { if (numeric & 0x8000) safe_strncpy(name, "default", len); @@ -169,5 +169,5 @@ } } - if (numeric & 0x0FFF) { + if (numeric & FLAG_NUM_HOST) { safe_strncpy(name, inet_ntoa(sin->sin_addr), len); return (0); Thanks, Tom Vajzovic