1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#include <errno.h>
#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/utsname.h>
int kernel_version;
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
void get_kernel_version(void)
{
static struct utsname uts;
int x = 0, y = 0, z = 0;
if (uname(&uts) == -1) {
fprintf(stderr, "Unable to retrieve kernel version.\n");
return;
}
sscanf(uts.release, "%d.%d.%d", &x, &y, &z);
kernel_version = LINUX_VERSION(x, y, z);
}
static jmp_buf env;
void throw_exception(int err)
{
longjmp(env, err);
}
int wrap_parse(int (*fn)(int, char **, int, unsigned int *, void *, void **),
int i, char **argv, int inv, unsigned int *flags, void *p,
void **mptr)
{
int rv = -1;
int err;
if ((err = setjmp(env)) == 0) {
rv = fn(i, argv, inv, flags, p, mptr);
} else {
errno = err;
}
return rv;
}
struct ipt_ip;
void wrap_save(int (*fn)(const void *, const void *),
const void *ip, const void *m)
{
fn(ip, m);
fprintf(stdout, "\n"); /* make sure something is written to stdout */
fflush(stdout);
}
int wrap_x6fn(void (*fn)(void *), void *data)
{
int err;
if ((err = setjmp(env)) == 0) {
fn(data);
} else {
errno = err;
return -err;
}
return 0;
}
int wrap_uintfn(void (*fn)(unsigned int), unsigned int data)
{
int err;
if ((err = setjmp(env)) == 0) {
fn(data);
} else {
errno = err;
return -err;
}
return 0;
}
int wrap_voidfn(void (*fn)(void))
{
int err;
if ((err = setjmp(env)) == 0) {
fn();
} else {
errno = err;
return -err;
}
return 0;
}
|