From owner-freebsd-net Thu Jul 11 10:56:38 2002 Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 494A037B400 for ; Thu, 11 Jul 2002 10:56:35 -0700 (PDT) Received: from kronos.networkrichmond.com (kronos.networkrichmond.com [64.240.180.22]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7043443E5E for ; Thu, 11 Jul 2002 10:56:34 -0700 (PDT) (envelope-from kbyanc@posi.net) X-Provider: NetworkRichmond, Inc. http://www.networkrichmond.com/ Received: from localhost (kbyanc@localhost) by kronos.networkrichmond.com (8.9.3/8.9.3/antispam) with ESMTP id NAA34575; Thu, 11 Jul 2002 13:56:28 -0400 (EDT) Date: Thu, 11 Jul 2002 13:56:28 -0400 (EDT) From: Kelly Yancey X-Sender: kbyanc@kronos.networkrichmond.com To: Juan Francisco Rodriguez Hervella Cc: freebsd-net@FreeBSD.ORG Subject: Re: sysctl inferface question In-Reply-To: <3D2D9D4E.74A1B6F4@it.uc3m.es> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org On Thu, 11 Jul 2002, Juan Francisco Rodriguez Hervella wrote: > Hello: > > I'm very confused with the sysctl internals. > > For example, looking at the kernel source code of FreeBSD, I've realized > > of the following: > > netinet/in_proco.c: > SYSCTL_NODE(_net_inet6, IPPROTO_DIVERT, divert, > CTLFLAG_RW, 0, "DIVERT"); > netinet/ip_divert.c: > SYSCTL_DECL(_net_inet_divert); > netinet/ip_divert.c: > SYSCTL_PROC(_net_inet_divert, OID_AUTO, pcblist, CTLFLAG_RD, > 0, 0, > div_pcblist, "S,xinpcb", "List of active divert sockets"); > > Isn't this redundant ? I mean, if there is a "SYSCTL_NODE", there is > *no* need for having > "SYSCTL_DECL" in "ip_divert.c"... I am wrong ? > It is a scoping/linking issue: the SYSCTL_DECL is needed in netinet/ip_divert.c so that children may be added to the node which was defined in netinet/in_proto.c. Without it, the very next line in netinet/ip_divert would fail to compile because it coulding find the parent node. A good C reference would probably better explain the difference between declaring a variable and defining a variable, but that is exactly the difference you are witnessing here. > Also, I don't undertand the meaning of the "fmt" field....what is it for > ? What's the > meaning of "S,xinpcb" in the above example ? > > Thanks. > > -- > JFRH. > The fmt field is used by sysctl(8) to format the data returned from the kernel. The "S,xinpcb" format string tells sysctl(8) to use it's definition of "xinpcb" formatting to render the structure. Take a look at /usr/src/sbin/sysctl/sysctl.c; it is a pretty light read. Good luck, Kelly -- Kelly Yancey -- kbyanc@{posi.net,FreeBSD.org} To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message