sysctl string on FreeBSD

The way to 'sysctl' string in the kernel module program

The sysctl_proc function:

char sysctl_str[1024];
static int
sysctl_str_ctrl(SYSCTL_HANDLER_ARGS)
{
   int error;
   char *p;
   p = sysctl_str;
   error = sysctl_handle_string(oidp, p, sizeof(sysctl_str), req);
   if (!error && req->newptr) {
      //
   }
   error = SYSCTL_OUT(req, sysctl_str, sizeof(sysctl_str));
   return error;
}

Note: SYSCTL_OUT sends the value to user space, that is to update the MIB value.

SYSCTL_ADD_PROC(NULL, SYSCTL_CHILDREN(sysctl_root), OID_AUTO, "str", 
   CTLTYPE_STRING|CTLFLAG_RW, 0, sizeof(sysctl_str), sysctl_str_ctrl, "A", "");