dev/c/sysctl_ex/_sysctl_ex.c

64 lines
1.3 KiB
C

#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <linux/sysctl.h>
#include <errno.h>
int _sysctl(struct __sysctl_args *args );
#define OSNAMESZ 100
void test0_osname()
{
struct __sysctl_args args;
char osname[OSNAMESZ];
size_t osnamelth;
int name[] = { CTL_KERN, KERN_OSTYPE };
memset(&args, 0, sizeof(struct __sysctl_args));
args.name = name;
args.nlen = sizeof(name)/sizeof(name[0]);
args.oldval = osname;
args.oldlenp = &osnamelth;
osnamelth = sizeof(osname);
if (syscall(SYS__sysctl, &args) == -1) {
perror("_sysctl");
exit(EXIT_FAILURE);
}
printf("This machine is running %*s\n", (int)osnamelth, osname);
}
void test1_tcp_max_syn_backlog()
{
struct __sysctl_args args;
int var;
size_t var_len;
int name[] = { CTL_NET, NET_IPV4, NET_TCP_MAX_SYN_BACKLOG };
memset(&args, 0, sizeof(struct __sysctl_args));
args.name = name;
args.nlen = sizeof(name)/sizeof(name[0]);
args.oldval = &var;
args.oldlenp = &var_len;
if (syscall(SYS__sysctl, &args) == -1) {
perror("_sysctl");
exit(EXIT_FAILURE);
}
printf("NET_TCP_MAX_SYN_BACKLOG = %u\n", var);
}
int
main(void)
{
test0_osname();
test1_tcp_max_syn_backlog();
exit(EXIT_SUCCESS);
}