On Oct 25, 2011, at 8:17 PM, Sean Mahood wrote:

> Hello,
> 
> I noticed that when doing a netstat -s (running on a kernel without SCTP 
> support compiled in), I get the following message output to stderr:
> 
> netstat: sysctl: net.inet.sctp.stats: No such file or directory
> 
> Wondering why it would attempt to fetch SCTP stats when it was compiled out 
> of the kernel, I noted that netstat could be compiled without SCTP support as 
> well, but that there is no good way to link the two compilation conditions, 
> or to have a generic binary that can run without error regardless of compiled 
> kernel options.
> 
> To that end, I added a method to check for environment compatibility in 
> netstat. For SCTP specifically, I used the FEATURE macros and added SCTP as a 
> FEATURE.
> 
> Other protocols could also be configured to be checked at runtime if desired, 
> though I haven't implemented any others at this time.
Hi Sean,

I agree, the error message should be avoided. There is a similar situation for 
IPv6. When not compiled
into the kernel, netstat should not report an error, even if it is not 
recompiled. The way it is
handled for INET6 is to pay attention to the errno in case sysctlbyname() 
fails. we also have already
one place in the sctp.c code where we do the correct check. I guess it was 
missed in the code
responsable for the above error message.

So what do you think about the attached patch, which resolves the issue you 
reported in a way already
used in netstat and which is portable to other BSD based platform (like Mac OS 
X)?

Thank you very much for reporting the issue.

Best regards
Michael

Index: sctp.c
===================================================================
--- sctp.c      (revision 230008)
+++ sctp.c      (working copy)
@@ -611,7 +611,8 @@
                        memset(&zerostat, 0, len);
                if (sysctlbyname("net.inet.sctp.stats", &sctpstat, &len,
                    zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
-                       warn("sysctl: net.inet.sctp.stats");
+                       if (errno != ENOENT)
+                               warn("sysctl: net.inet.sctp.stats");
                        return;
                }
        } else



> 
> -- Sean
> 
> 
> 
> <main.c.diff><netstat.h.diff><sctp.c.diff><sctp_sysctl.c.diff>_______________________________________________
> freebsd-net@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-net
> To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"

_______________________________________________
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"

Reply via email to