From: Vadim Kochan <[email protected]>

Use helpers from sysctl.c module to set sock memory params
via /proc/sys/net/core.

Signed-off-by: Vadim Kochan <[email protected]>
---
 ifpps/Makefile   |  1 +
 sock.c           | 41 +++++++++--------------------------------
 trafgen/Makefile |  1 +
 3 files changed, 11 insertions(+), 32 deletions(-)

diff --git a/ifpps/Makefile b/ifpps/Makefile
index 110e6aa..096a853 100644
--- a/ifpps/Makefile
+++ b/ifpps/Makefile
@@ -11,6 +11,7 @@ ifpps-objs =  xmalloc.o \
                sig.o \
                screen.o \
                die.o \
+               sysctl.o \
                ifpps.o
 
 ifpps-eflags = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) 
--cflags ncurses 2> /dev/null)
diff --git a/sock.c b/sock.c
index cfca05e..84723d0 100644
--- a/sock.c
+++ b/sock.c
@@ -10,6 +10,7 @@
 #include "str.h"
 #include "linktype.h"
 #include "built_in.h"
+#include "sysctl.h"
 
 int af_socket(int af)
 {
@@ -149,50 +150,26 @@ enum {
 #define SMEM_SUG_DEF   4194304
 
 static const char *const sock_mem[] = {
-       [sock_rmem_max] = "/proc/sys/net/core/rmem_max",
-       [sock_rmem_def] = "/proc/sys/net/core/rmem_default",
-       [sock_wmem_max] = "/proc/sys/net/core/wmem_max",
-       [sock_wmem_def] = "/proc/sys/net/core/wmem_default",
+       [sock_rmem_max] = "net/core/rmem_max",
+       [sock_rmem_def] = "net/core/rmem_default",
+       [sock_wmem_max] = "net/core/wmem_max",
+       [sock_wmem_def] = "net/core/wmem_default",
 };
 
 static int get_system_socket_mem(int which)
 {
-       int fd, val = -1;
-       ssize_t ret;
-       const char *file = sock_mem[which];
-       char buff[64];
+       int val;
 
-       fd = open(file, O_RDONLY);
-       if (fd < 0)
-               return val;
+       if (sysctl_get_int(sock_mem[which], &val))
+               return -1;
 
-       ret = read(fd, buff, sizeof(buff));
-       if (ret > 0)
-               val = atoi(buff);
-
-       close(fd);
        return val;
 }
 
 static void set_system_socket_mem(int which, int val)
 {
-       int fd;
-       const char *file = sock_mem[which];
-       ssize_t ret;
-       char buff[64];
-
-       fd = open(file, O_WRONLY);
-       if (fd < 0)
-               return;
-
-       memset(buff, 0, sizeof(buff));
-       slprintf(buff, sizeof(buff), "%d", val);
-
-       ret = write(fd, buff, strlen(buff));
-       if (ret < 0)
+       if (sysctl_set_int(sock_mem[which], val))
                panic("Cannot set system socket memory!\n");
-
-       close(fd);
 }
 
 void set_system_socket_memory(int *vals, size_t len)
diff --git a/trafgen/Makefile b/trafgen/Makefile
index 3cb8497..9777485 100644
--- a/trafgen/Makefile
+++ b/trafgen/Makefile
@@ -17,6 +17,7 @@ trafgen-objs =        xmalloc.o \
                ring_tx.o \
                ring.o \
                timer.o \
+               sysctl.o \
                trafgen_lexer.yy.o \
                trafgen_parser.tab.o \
                trafgen.o
-- 
2.4.2

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to