Date: Wed, 4 Dec 2013 05:06:56 +0000 (UTC) From: Eitan Adler <eadler@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r258908 - head/sbin/route Message-ID: <201312040506.rB456u6r058512@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: eadler Date: Wed Dec 4 05:06:56 2013 New Revision: 258908 URL: http://svnweb.freebsd.org/changeset/base/258908 Log: Avoid using a static buffer in atalk_ntoa. This will help allow users to call route(1) as a library. Submitted by: Sebastian Huber <sebastian.huber@embedded-brains.de> (older version) Discussed on: -hackers Reviwed by: adri (different older version) Modified: head/sbin/route/route.c Modified: head/sbin/route/route.c ============================================================================== --- head/sbin/route/route.c Wed Dec 4 04:29:52 2013 (r258907) +++ head/sbin/route/route.c Wed Dec 4 05:06:56 2013 (r258908) @@ -71,6 +71,8 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> #include <ifaddrs.h> +#define ATALK_BUF_SIZE 20 + static struct keytab { const char *kt_cp; int kt_i; @@ -92,7 +94,7 @@ static int defaultfib; static int numfibs; static int atalk_aton(const char *, struct at_addr *); -static char *atalk_ntoa(struct at_addr); +static char *atalk_ntoa(struct at_addr, char [ATALK_BUF_SIZE]); static void printb(int, const char *); static void flushroutes(int argc, char *argv[]); static int flushroutes_fib(int); @@ -495,6 +497,7 @@ routename(struct sockaddr *sa) { struct sockaddr_dl *sdl; const char *cp; + char atalk_buf[ATALK_BUF_SIZE]; static char line[NI_MAXHOST]; static char domain[MAXHOSTNAMELEN + 1]; static int first = 1; @@ -577,7 +580,8 @@ routename(struct sockaddr *sa) #endif case AF_APPLETALK: (void)snprintf(line, sizeof(line), "atalk %s", - atalk_ntoa(((struct sockaddr_at *)(void *)sa)->sat_addr)); + atalk_ntoa(((struct sockaddr_at *)(void *)sa)->sat_addr, + atalk_buf)); break; case AF_LINK: @@ -622,6 +626,7 @@ netname(struct sockaddr *sa) { struct sockaddr_dl *sdl; static char line[MAXHOSTNAMELEN + 1]; + char atalk_buf[ATALK_BUF_SIZE]; int n; #ifdef INET struct netent *np = NULL; @@ -685,7 +690,8 @@ netname(struct sockaddr *sa) case AF_APPLETALK: (void)snprintf(line, sizeof(line), "atalk %s", - atalk_ntoa(((struct sockaddr_at *)(void *)sa)->sat_addr)); + atalk_ntoa(((struct sockaddr_at *)(void *)sa)->sat_addr, + atalk_buf)); break; case AF_LINK: @@ -1858,6 +1864,7 @@ keyword(const char *cp) static void sodump(struct sockaddr *sa, const char *which) { + char atalk_buf[ATALK_BUF_SIZE]; #ifdef INET6 char nbuf[INET6_ADDRSTRLEN]; #endif @@ -1882,7 +1889,8 @@ sodump(struct sockaddr *sa, const char * #endif case AF_APPLETALK: (void)printf("%s: atalk %s; ", which, - atalk_ntoa(((struct sockaddr_at *)(void *)sa)->sat_addr)); + atalk_ntoa(((struct sockaddr_at *)(void *)sa)->sat_addr, + atalk_buf)); break; } (void)fflush(stdout); @@ -1952,11 +1960,9 @@ atalk_aton(const char *text, struct at_a } static char * -atalk_ntoa(struct at_addr at) +atalk_ntoa(struct at_addr at, char buf[ATALK_BUF_SIZE]) { - static char buf[20]; - - (void)snprintf(buf, sizeof(buf), "%u.%u", ntohs(at.s_net), at.s_node); - buf[sizeof(buf) - 1] = '\0'; + (void)snprintf(buf, ATALK_BUF_SIZE, "%u.%u", ntohs(at.s_net), at.s_node); + buf[ATALK_BUF_SIZE - 1] = '\0'; return(buf); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201312040506.rB456u6r058512>