BSD-Sysctl
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
/* Sysctl.xs -- XS component of BSD-Sysctl
*
* Copyright (C) 2006-2014 David Landgren
*/
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
/* define _FreeBSD_version where applicable */
#if __FreeBSD__ >= 2
#include <osreldate.h>
#endif
#include <stdio.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/time.h> /* struct clockinfo */
#include <sys/vmmeter.h> /* struct vmtotal */
#include <sys/resource.h> /* struct loadavg */
#if __FreeBSD_version < 1000000
#include <sys/mbuf.h> /* struct mbstat (opaque mib) */
#endif
#include <sys/timex.h> /* struct ntptimeval (opaque mib) */
#include <sys/devicestat.h> /* struct devstat (opaque mib) */
#include <sys/mount.h> /* struct xvfsconf (opaque mib) */
/* prerequisites for TCP/IP-related structs */
#include <arpa/inet.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#if __FreeBSD_version < 500000
#include <netinet/tcp.h> /* struct tcpstat prerequisite */
#endif
#include <netinet/icmp_var.h> /* struct icmpstat */
#include <netinet/igmp_var.h> /* struct igmpstat */
#include <netinet/tcp_var.h> /* struct tcpstat */
/* prerequisites for struct udpstat */
#include <netinet/in.h>
#include <netinet/ip_var.h>
#include <netinet/udp.h>
#include <netinet/udp_var.h>
#include <netinet6/raw_ip6.h>
#include "bsd-sysctl.h"
int
_init_iterator(HV *self, int *mib, int *miblenp, int valid) {
SV **headp;
int qoid[CTL_MAXNAME];
u_int qoidlen;
SV *clen;
SV **clenp;
int cmplen;
int j;
qoid[0] = 0;
qoid[1] = 2;
if (valid) {
memcpy(qoid+2, mib, (*miblenp) * sizeof(int));
qoidlen = *miblenp + 2;
*miblenp = (CTL_MAXNAME+2) * sizeof(int);
clenp = hv_fetch(self, "_len", 4, 0);
cmplen = SvIV(*clenp);
}
else {
headp = hv_fetch(self, "head", 4, 0);
if (!(headp && *headp)) {
croak( "failed to get some head in _init_iterator()\n" );
}
if (SvPOK(*headp)) {
/* begin where asked */
qoidlen = sizeof(qoid);
if (sysctlnametomib( SvPV_nolen(*headp), qoid+2, (size_t*)&qoidlen) == -1) {
warn( "_init_iterator(%s): sysctlnametomib lookup failed\n",
SvPV_nolen(*headp)
);
return 0;
}
cmplen = qoidlen;
qoidlen += 2;
}
else {
/* begin at the beginning */
qoid[2] = 1;
cmplen = 0;
qoidlen = 3;
}
clen = newSViv(cmplen);
SvREFCNT_inc(clen);
hv_store(self, "_len", 4, clen, 0);
}
/*
printf( "next: " );
for (j = 0; j < qoidlen; ++j) {
if (j) printf("."); printf("%d", qoid[j]);
}
printf("\n");
*/
/* load the mib */
if (sysctl(qoid, qoidlen, mib, (size_t*)miblenp, 0, 0) == -1) {
return 0;
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.106 second using v1.00-cache-2.02-grep-82fe00e-cpan-9f2165ba459b )