aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2014-10-02 22:56:02 +0800
committerglebius <glebius@FreeBSD.org>2014-10-02 22:56:02 +0800
commit1d499228c5c98823d333eed2ef10ff8e228d573a (patch)
tree52573c14ae10bf3973f8ef2adfa4f012408939d9 /net
parentc03d0c6606e4e3464946665dc8c4e0ba2d27527e (diff)
downloadfreebsd-ports-gnome-1d499228c5c98823d333eed2ef10ff8e228d573a.tar.gz
freebsd-ports-gnome-1d499228c5c98823d333eed2ef10ff8e228d573a.tar.zst
freebsd-ports-gnome-1d499228c5c98823d333eed2ef10ff8e228d573a.zip
Patch cnd so that it uses getifaddrs(3) instead of nosing
in kernel memory via kvm(3). This fixes breakage on head, as well as avoid breakages in the future. Approved by: lme
Diffstat (limited to 'net')
-rw-r--r--net/cnd/Makefile1
-rw-r--r--net/cnd/files/patch-Makefile13
-rw-r--r--net/cnd/files/patch-main.c248
3 files changed, 259 insertions, 3 deletions
diff --git a/net/cnd/Makefile b/net/cnd/Makefile
index 9acd0c16f244..bbdbf623a273 100644
--- a/net/cnd/Makefile
+++ b/net/cnd/Makefile
@@ -3,6 +3,7 @@
PORTNAME= cnd
PORTVERSION= 0.7
+PORTREVISION= 1
CATEGORIES= net
MASTER_SITES= http://www.bsd-geek.de/FreeBSD/distfiles/
diff --git a/net/cnd/files/patch-Makefile b/net/cnd/files/patch-Makefile
index 7a4625e8490f..f71603ee1c27 100644
--- a/net/cnd/files/patch-Makefile
+++ b/net/cnd/files/patch-Makefile
@@ -1,8 +1,15 @@
---- ./Makefile.orig 2011-06-21 13:15:49.000000000 +0200
-+++ ./Makefile 2011-06-21 13:16:07.000000000 +0200
-@@ -1,4 +1,4 @@
+--- Makefile.orig 2005-03-03 08:59:05.000000000 +0300
++++ Makefile 2014-10-02 18:10:01.000000000 +0400
+@@ -1,10 +1,10 @@
-CC = cc
+CC ?= cc
CFLAGS += -Wall
PREFIX ?= /usr/local
OBJS = main.o
+
+ all: $(OBJS)
+- $(CC) $(CFLAGS) -o cnd $(OBJS) -lcurses -lkvm
++ $(CC) $(CFLAGS) -o cnd $(OBJS) -lcurses
+ .c.o:
+ $(CC) $(CFLAGS) -c -I/usr/include/ -o $@ $<
+ .SUFFIXS: .c .o
diff --git a/net/cnd/files/patch-main.c b/net/cnd/files/patch-main.c
new file mode 100644
index 000000000000..ea4b09eaf177
--- /dev/null
+++ b/net/cnd/files/patch-main.c
@@ -0,0 +1,248 @@
+--- main.c.orig 2014-10-02 17:44:25.000000000 +0400
++++ main.c 2014-10-02 18:08:23.000000000 +0400
+@@ -41,14 +41,13 @@
+ #include <sys/time.h>
+ #include <stdarg.h>
+ #include <errno.h>
++#include <ifaddrs.h>
+
+ #include <sys/socket.h>
+ #include <net/if.h>
+-#include <net/if_var.h>
+ #include <net/if_types.h>
+
+ #include <fcntl.h>
+-#include <kvm.h>
+
+ #include <curses.h>
+
+@@ -59,21 +58,10 @@
+ #define DISP_BYTE 1
+ int disp_format = DISP_BYTE;
+
+-struct nlist netl[] = { {"_ifnet"}, {""} };
+-kvm_t *kvmd;
+-char *nlistf = NULL;
+-char *memf = NULL;
+-#if __FreeBSD_version >= 501113
+-char name[IFNAMSIZ];
+-#else
+-char name[32];
+-char tname[16];
+-#endif
+-unsigned long ifnetaddr = 0;
+-
+ unsigned long long in_total = 0;
+ unsigned long long out_total = 0;
+ char *in_dev = NULL;
++char name[IFNAMSIZ];
+
+ int winw,winh;
+ WINDOW *mainw;
+@@ -173,7 +161,6 @@
+ getmaxyx(stdscr,winh,winw);
+ if(winh < 20 || winw < 20) {
+ endwin();
+- kvm_close(kvmd);
+ fprintf(stderr,"Screen size is too small, sorry\n");
+ exit(1);
+ }
+@@ -241,35 +228,37 @@
+ return;
+ }
+
+-/* read kernel memory, based off of netstat */
+-int kread(u_long addr,char *buf,int size) {
+- if(kvmd != NULL) {
+- if(kvm_nlist(kvmd,netl) < 0) {
+- if(nlistf)
+- fprintf(stderr,"error, kvm_nlist(%s): %s\n",nlistf,kvm_geterr(kvmd));
+- else
+- fprintf(stderr,"error, kvm_nlist: %s\n",kvm_geterr(kvmd));
+- exit(1);
+- }
+-
+- if(netl[0].n_type == 0) {
+- if(nlistf)
+- fprintf(stderr,"error, no namelist: %s\n",nlistf);
+- else
+- fprintf(stderr,"error, no namelist\n");
+- exit(1);
+- }
+- } else {
+- fprintf(stderr,"error, kvm not available\n");
++void readstat(u_long *ibytes, u_long *obytes)
++{
++ struct ifaddrs *ifap, *ifa;
++
++ if (getifaddrs(&ifap) != 0) {
++ fprintf(stderr,"getifaddrs()\n");
+ exit(1);
+ }
+- if(!buf)
+- return 0;
+- if(kvm_read(kvmd,addr,buf,size) != size) {
+- fprintf(stderr,"error, %s\n",kvm_geterr(kvmd));
++
++ for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
++ if (ifa->ifa_addr->sa_family != AF_LINK)
++ continue;
++ if (in_dev != NULL) {
++ if (strcmp(ifa->ifa_name, in_dev) == 0)
++ break;
++ } else
++ break;
++ }
++ if (ifa == NULL) {
++ fprintf(stderr,"error, interface not found\n");
+ exit(1);
+ }
+- return 0;
++
++ strncpy(name, ifa->ifa_name, IFNAMSIZ);
++
++#define IFA_STAT(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s)
++ *ibytes = IFA_STAT(ibytes);
++ *obytes = IFA_STAT(obytes);
++#undef IFA_STAT
++
++ freeifaddrs(ifap);
+ }
+
+ int main(int argc, char *argv[]) {
+@@ -280,9 +269,6 @@
+ unsigned long curo = 0;
+ #define CURIS curi / timea.tv_sec
+ #define CUROS curo / timea.tv_sec
+- /* all goods are defined in net/if.h and net/if_var.h */
+- struct ifnet foonet;
+- struct ifnethead ifnethead;
+ int i = 0;
+ int x = 0;
+ int j = 0;
+@@ -393,48 +379,10 @@
+ argc -= optind;
+ argv += optind;
+
+- for(i=0;i<sizeof(name);i++) {
+- name[i] = '\0';
+- }
+-
+- kvmd = kvm_openfiles(nlistf,memf,NULL,O_RDONLY,0);
+ setgid(getgid());
+- kread(0,0,0);
+- ifnetaddr = netl[0].n_value;
+-
+- if(kread(ifnetaddr,(char *)&ifnethead,sizeof ifnethead))
+- return 1;
+-
+- ifnetaddr = (u_long)TAILQ_FIRST(&ifnethead);
+- if(kread(ifnetaddr,(char *)&foonet,sizeof foonet))
+- return 1;
+-
+-#if __FreeBSD_version >= 501113
+- strncpy(name,foonet.if_xname,sizeof(name));
+-#else
+- if(kread((u_long)foonet.if_name, tname, 16))
+- return 1;
+- snprintf(name,32,"%s%d",tname,foonet.if_unit);
+-#endif
+-
+- while(in_dev != NULL && strncmp(in_dev,name,strlen(in_dev)) != 0) {
+- ifnetaddr = (u_long)TAILQ_NEXT(&foonet,if_link);
+- if(ifnetaddr < 1) {
+- fprintf(stderr,"error, interface not found\n");
+- exit(1);
+- }
+- if(kread(ifnetaddr,(char *)&foonet,sizeof foonet))
+- return 1;
+-
+-#if __FreeBSD_version >= 501113
+- strncpy(name,foonet.if_xname,sizeof(name));
+-#else
+- if(kread((u_long)foonet.if_name, tname, 16))
+- return 1;
+- snprintf(name,32,"%s%d",tname,foonet.if_unit);
+-#endif
+-
+- }
++
++ readstat(&lasti, &lasto);
++ gettimeofday(&last,NULL);
+
+ /* start curses */
+ initscr();
+@@ -486,37 +434,32 @@
+ }
+ /* screen init.. */
+ screen_init();
+-
+- lasti = foonet.if_ibytes;
+- lasto = foonet.if_obytes;
+- gettimeofday(&last,NULL);
+-
++
+ for(i=0;i<MAX_G;i++) {
+ logi[i] = NULL;
+ logo[i] = NULL;
+ }
+
+ for(;;) {
++ u_long ibytes, obytes;
++
+ screen_check();
+ ch = wgetch(mainw);
+ /* quit when we get 'q' */
+ if(ch == (int)'q' || ch == (int)' ') {
+
+ endwin();
+- kvm_close(kvmd);
+
+ exit(0);
+ }
+ /* clear screen */
+ if(ch == (int)'c') {
+- free_logs();
++ free_logs();
+ }
+-
+- if(kread(ifnetaddr,(char *)&foonet,sizeof foonet))
+- return 1;
+-
+- curi = foonet.if_ibytes - lasti;
+- curo = foonet.if_obytes - lasto;
++
++ readstat(&ibytes, &obytes);
++ curi = ibytes - lasti;
++ curo = obytes - lasto;
+ in_total += curi;
+ out_total += curo;
+
+@@ -569,7 +512,6 @@
+ logi[i] = (unsigned int *)malloc(sizeof(unsigned int));
+ if(logi[i] == NULL) {
+ fprintf(stderr,"error,allocating memory\n");
+- kvm_close(kvmd);
+ endwin();
+ exit(1);
+ }
+@@ -583,7 +525,6 @@
+ logo[i] = (unsigned int *)malloc(sizeof(unsigned int));
+ if(logo[i] == NULL) {
+ fprintf(stderr,"error,allocating memory\n");
+- kvm_close(kvmd);
+ endwin();
+ exit(1);
+ }
+@@ -648,9 +589,8 @@
+
+ gettimeofday(&last,NULL);
+ select(0,NULL,NULL,NULL,&timea);
+- lasti = foonet.if_ibytes;
+- lasto = foonet.if_obytes;
+-
++ lasti = ibytes;
++ lasto = obytes;
+ }
+ }
+