From 96b0404ad3e2f0910929fb89927dd94502a944cd Mon Sep 17 00:00:00 2001 From: dmitry pervushin Date: Wed, 24 Apr 2013 21:22:58 +0200 Subject: Added license header --- netfilter/Makefile | 25 +++++++++++++++++++++++ netfilter/nl.c | 59 +++++++++++++++++++----------------------------------- 2 files changed, 46 insertions(+), 38 deletions(-) create mode 100644 netfilter/Makefile diff --git a/netfilter/Makefile b/netfilter/Makefile new file mode 100644 index 0000000..02d4e87 --- /dev/null +++ b/netfilter/Makefile @@ -0,0 +1,25 @@ +############################################################################# +# Copyright (c) 2013 Linaro +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Linaro +############################################################################# + +CC = $(CROSS_COMPILE)gcc +CFLAGS = -O2 -g +NLEXE = nl-listener +Q = @ + +$(NLEXE): nl.c + @echo -ne "\tCC\t" + @echo $< + $(Q)$(CC) $(CFLAGS) -I. -o $@ $< + +clean: + @echo -ne "\tRM\t" + @echo $(NLEXE) + $(Q)$(RM) $(NLEXE) diff --git a/netfilter/nl.c b/netfilter/nl.c index ca71ca0..68c8b7c 100644 --- a/netfilter/nl.c +++ b/netfilter/nl.c @@ -1,8 +1,13 @@ -#include -#include -#include -#include -#include +/******************************************************************************* + * Copyright (c) 2013 Linaro + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Linaro + *******************************************************************************/ #include #include #include @@ -11,39 +16,18 @@ #include #include #include +#include +#include +#include +#include +#include enum type_t { TYPE_SYSFS, TYPE_NETLINK, }; -int dump(void *_a, size_t s) -{ - size_t i, j; - unsigned char *p = _a; - - for (i = 0; i < s; i += 16) { - for (j = 0; j < 16; j ++ ) { - if (j == 8) - printf(" - "); - if (i + j > s) { - printf(" "); - } else { - printf("%c", (isprint(p[i+j])) ? p[i+j] : '.'); - } - } - printf(" "); - for (j = 0; j < 16; j ++ ) { - if (j == 8) - printf(" - "); - printf("%02X ", p[i+j]); - } - printf("\n"); - } - return 0; -} - -int sysfs_handle_open(char *name) +static int sysfs_handle_open(char *name) { char sysfs[256] = "/sys/devices/virtual/xt_idletimer/timers/"; char buffer[256]; @@ -57,18 +41,14 @@ int sysfs_handle_open(char *name) return r; } -#define sysfs_handle_close(h) close(h) - -int netlink_socket_open(struct sockaddr_nl *s_nladdr) +static int netlink_socket_open(struct sockaddr_nl *s_nladdr) { int fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT); bind(fd, (struct sockaddr*)s_nladdr, sizeof(*s_nladdr)); return fd; } -#define netlink_socket_close(h) close(h) - -int do_wait(char *nick, enum type_t type, int seconds) +static int do_wait(char *nick, enum type_t type, int seconds) { struct pollfd pfd; int r; @@ -131,6 +111,9 @@ int do_wait(char *nick, enum type_t type, int seconds) continue; printf("%s\n", ptr); } + + close(pfd.fd); + return 1; } -- cgit v1.2.3