Asistence with sysctl proc's handle in kernel space

From: Nimbly2329 <hjlftdygaqf_at_use.startmail.com>
Date: Wed, 10 Jul 2024 21:04:49 UTC
I am following FreeBSD drivers: A guide for the intrepid by Joseph Kong to
learn to write FreeBSD device drivers.  

  

I got to the sysctl subchapter where is more or less this code  

  

#include <sys/param.h>  

#include <sys/sysctl.h>  

  

....  

  

static int sysctl_set_buffer_size(SYSCTL_HANDLER_ARGS) {  

int error = 0;  

int size = echo_message->buffer_size;  

error = sysctl_handle_int(oidp, &size, 0, req);  

if (error || !req->newptr || echo_message->buffer_size == size) return
(error);  

if (size >= 128 && size <= 512) {  

echo_message->buffer = realloc(echo_message->buffer, size, M_ECHO, M_WAITOK);  

echo_message->buffer_size = size;  

if (echo_message->length >= size) {  

echo_message->length = size - 1;  

echo_message->buffer[size - 1] = '\0';  

}  

} else {  

error = EINVAL;  

}  

return (error);  

}  

  

but when compiling I got the error:  

  

error: call to undeclared function 'sysctl_int_handle'; ISO C99 and later do
not support implicit function declarations [-Werror,-Wimplicit-function-
declaration]  

167 | error = sysctl_int_handle(oidp, &size, 0, req);  

  

instead of compiling.  

  

Which gets me to the point how are I supposed to get the value that the user
is trying to set with the sysctl utility, as well as report back the current
value, if had been a change, and if so the new value?