From owner-svn-ports-all@FreeBSD.ORG Thu Oct 2 14:56:03 2014 Return-Path: Delivered-To: svn-ports-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E971FE66; Thu, 2 Oct 2014 14:56:03 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id CA278E11; Thu, 2 Oct 2014 14:56:03 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s92Eu3gp023156; Thu, 2 Oct 2014 14:56:03 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s92Eu3r4023147; Thu, 2 Oct 2014 14:56:03 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201410021456.s92Eu3r4023147@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Thu, 2 Oct 2014 14:56:03 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r369827 - in head/net/cnd: . files X-SVN-Group: ports-head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-ports-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the ports tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Oct 2014 14:56:04 -0000 Author: glebius (src committer) Date: Thu Oct 2 14:56:02 2014 New Revision: 369827 URL: https://svnweb.freebsd.org/changeset/ports/369827 QAT: https://qat.redports.org/buildarchive/r369827/ Log: 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 Added: head/net/cnd/files/patch-main.c (contents, props changed) Modified: head/net/cnd/Makefile head/net/cnd/files/patch-Makefile Modified: head/net/cnd/Makefile ============================================================================== --- head/net/cnd/Makefile Thu Oct 2 14:06:13 2014 (r369826) +++ head/net/cnd/Makefile Thu Oct 2 14:56:02 2014 (r369827) @@ -3,6 +3,7 @@ PORTNAME= cnd PORTVERSION= 0.7 +PORTREVISION= 1 CATEGORIES= net MASTER_SITES= http://www.bsd-geek.de/FreeBSD/distfiles/ Modified: head/net/cnd/files/patch-Makefile ============================================================================== --- head/net/cnd/files/patch-Makefile Thu Oct 2 14:06:13 2014 (r369826) +++ head/net/cnd/files/patch-Makefile Thu Oct 2 14:56:02 2014 (r369827) @@ -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 Added: head/net/cnd/files/patch-main.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/net/cnd/files/patch-main.c Thu Oct 2 14:56:02 2014 (r369827) @@ -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 + #include + #include ++#include + + #include + #include +-#include + #include + + #include +-#include + + #include + +@@ -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= 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