From owner-freebsd-hackers@FreeBSD.ORG Thu Feb 12 05:56:23 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5DB7216A4CE for ; Thu, 12 Feb 2004 05:56:23 -0800 (PST) Received: from diaspar.rdsnet.ro (diaspar.rdsnet.ro [213.157.165.224]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8B9FA43D1D for ; Thu, 12 Feb 2004 05:56:22 -0800 (PST) (envelope-from dudu@diaspar.rdsnet.ro) Received: (qmail 88839 invoked by uid 89); 12 Feb 2004 13:56:17 -0000 Received: from unknown (HELO diaspar.rdsnet.ro) (dudu@diaspar.rdsnet.ro@213.157.165.224) by 0 with AES256-SHA encrypted SMTP; 12 Feb 2004 13:56:17 -0000 Date: Thu, 12 Feb 2004 15:56:15 +0200 From: Vlad Galu To: freebsd-hackers@freebsd.org Message-Id: <20040212155615.6124eacb.dudu@diaspar.rdsnet.ro> In-Reply-To: <20040124165621.GA19451@LapBSD.tin.it> References: <20040124165621.GA19451@LapBSD.tin.it> X-Mailer: Sylpheed version 0.9.9 (GTK+ 1.2.10; i386-portbld-freebsd4.9) Mime-Version: 1.0 Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg="pgp-sha1"; boundary="Signature=_Thu__12_Feb_2004_15_56_15_+0200_2YDVQLeawO=xG1AD" Subject: Re: help sysctl.h X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Feb 2004 13:56:23 -0000 --Signature=_Thu__12_Feb_2004_15_56_15_+0200_2YDVQLeawO=xG1AD Content-Type: text/plain; charset=US-ASCII Content-Disposition: inline Content-Transfer-Encoding: 7bit Nate Grey writes: |Hello, | |I'm trying to write a little program which retrieve the value 'sysctl |hw.acpi.thermal.tz0.temperature', I want to write it in C, through |sys/sysctl.h, but I'm a newbie C coder, so can anyone show me how to |assign to a var the value stored in that sysctl using sysctl C call? |I have read 'man 3 sysctl' but I didn't understand very well... | |P.S. |1) Sorry for my English |2) I'm not a list subscriber so please cc: | This is simple. Let's try a read example first: -- cut here -- #include #include #include int main() { int ret; /* here we will place our result */ int size = sizeof(ret); /* this is the storage size of the variable we put our result into */ sysctlbyname("net.inet.ip.forwarding", (void *)&ret, &size, NULL, NULL); return ret; } -- and here -- As you can see, after the pointers to ret and size, we had two NULL pointers. This means we didn't want to write anything to the sysctl. Let's see how to write the sysctl variable: -- cut here -- #include #include #include int main() { int ret = 1; int size = sizeof(ret); sysctlbyname("net.inet.ip.forwarding", NULL, NULL, (void *)&ret, size); return ret; } -- and here -- Now execute this proggie as root. After that, issue a 'sysctl net.inet.ip.forwarding' from the shell. You'll see that the sysctl value has changed. Hope this helps. I tried to give the simplest example possible. |Thanks in advance. Bye | |_______________________________________________ |freebsd-hackers@freebsd.org mailing list |http://lists.freebsd.org/mailman/listinfo/freebsd-hackers |To unsubscribe, send any mail to |"freebsd-hackers-unsubscribe@freebsd.org" | | |!DSPAM:402b8013604934185311595! | | | ---- If it's there, and you can see it, it's real. If it's not there, and you can see it, it's virtual. If it's there, and you can't see it, it's transparent. If it's not there, and you can't see it, you erased it. --Signature=_Thu__12_Feb_2004_15_56_15_+0200_2YDVQLeawO=xG1AD Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (FreeBSD) iD8DBQFAK4YBP5WtpVOrzpcRArcRAJ9f73t0klAdlhOT9kxloXoMaBLlsQCfU0+1 YGJGlkEoSwkxvpkzFe9cb7U= =FJO1 -----END PGP SIGNATURE----- --Signature=_Thu__12_Feb_2004_15_56_15_+0200_2YDVQLeawO=xG1AD--