Bug 57669

Summary: IFMIB(4) man page uses sysctl(3) incorrectly in example code
Product: Documentation Reporter: Ted Nolan <ted>
Component: Books & ArticlesAssignee: freebsd-doc (Nobody) <doc>
Status: Closed FIXED    
Severity: Affects Only Me CC: ted
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   

Description Ted Nolan 2003-10-06 19:10:10 UTC
The man page for ifmib(4) gives a code sample defining a function
get_ifmib_general().  This function uses the sysctl(3) function, but
with incorrect parameters.  The 4th parameter to sysctl(3) is the
_address_ of a location to read and store the size of the data;
however the example code places the actual size here, not the _location_
of the size.  The code will therefore give compilation warnings and
likely fail if run.

Fix: 

One way to fix it would be to declare a variable
	size_t len;

and replace the given sysctl() line with 2 lines:

	len = sizeof(*ifmd);
	return sysctl(name, 6, ifmd, &len, (void *)0, 0);
How-To-Repeat: Enter the code from the example, attempt to compile it with warnings
enabled.
Comment 1 Russell Francis 2003-10-14 12:19:53 UTC
Ted,

I saw your bug report at FreeBSD and thought I would let you know that
the changes you suggested have allready been made.  If you cvsup a more
recent version of FreeBSD you should see them.

Thanks,
Russ
Comment 2 Maxim Konovalov freebsd_committer freebsd_triage 2003-12-12 06:37:38 UTC
State Changed
From-To: open->closed

johan has fixed this bug in -CURRENT and -STABLE.