[PATCH] sbin/nos-tun WARNS=6 (no style)

Sepherosa Ziehau sepherosa at softhome.net
Tue Apr 12 03:10:25 PDT 2005


warn = 6 only1) WARNS=6
2) rename local variable to avoid name shadowing

Index: Makefile
===================================================================
RCS file: /opt/df_cvs/src/sbin/nos-tun/Makefile,v
retrieving revision 1.2
diff -u -r1.2 Makefile
--- Makefile	17 Jun 2003 04:27:34 -0000	1.2
+++ Makefile	11 Apr 2005 10:32:10 -0000
@@ -2,6 +2,7 @@
 # $DragonFly: src/sbin/nos-tun/Makefile,v 1.2 2003/06/17 04:27:34 dillon Exp $
 
 PROG=	nos-tun
+WARNS?=	6
 MAN=	nos-tun.8
 
 .include <bsd.prog.mk>
Index: nos-tun.c
===================================================================
RCS file: /opt/df_cvs/src/sbin/nos-tun/nos-tun.c,v
retrieving revision 1.5
diff -u -r1.5 nos-tun.c
--- nos-tun.c	18 Dec 2004 21:43:39 -0000	1.5
+++ nos-tun.c	11 Apr 2005 10:32:10 -0000
@@ -83,33 +83,35 @@
 
 static void usage(void);
 
-int Set_address(char *addr, struct sockaddr_in *sin)
+static int
+Set_address(char *addr, struct sockaddr_in *in)
 {
   struct hostent *hp;
 
-  bzero((char *)sin, sizeof(struct sockaddr));
-  sin->sin_family = AF_INET;
-  if((sin->sin_addr.s_addr = inet_addr(addr)) == (u_long)-1) {
+  bzero((char *)in, sizeof(struct sockaddr));
+  in->sin_family = AF_INET;
+  if((in->sin_addr.s_addr = inet_addr(addr)) == (u_long)-1) {
     hp = gethostbyname(addr);
     if (!hp) {
       syslog(LOG_ERR,"unknown host %s", addr);
       return 1;
     }
-    sin->sin_family = hp->h_addrtype;
-    bcopy(hp->h_addr, (caddr_t)&sin->sin_addr, hp->h_length);
+    in->sin_family = hp->h_addrtype;
+    bcopy(hp->h_addr, (caddr_t)&in->sin_addr, hp->h_length);
   }
   return 0;
 }
 
-int tun_open(char *devname, struct sockaddr *ouraddr, char *theiraddr)
+static int
+tun_open(char *dev_name, struct sockaddr *ouraddr, char *theiraddr)
 {
   int s;
-  struct sockaddr_in *sin;
+  struct sockaddr_in *in;
 
   /* Open tun device */
-  tun = open (devname, O_RDWR);
+  tun = open (dev_name, O_RDWR);
   if (tun < 0) {
-    syslog(LOG_ERR,"can't open %s - %m",devname);
+    syslog(LOG_ERR,"can't open %s - %m",dev_name);
     return(1);
   }
 
@@ -119,8 +121,8 @@
   bzero((char *)&ifra, sizeof(ifra));
   bzero((char *)&ifrq, sizeof(ifrq));
 
-  strncpy(ifrq.ifr_name, devname+5, IFNAMSIZ);
-  strncpy(ifra.ifra_name, devname+5, IFNAMSIZ);
+  strncpy(ifrq.ifr_name, dev_name + 5, IFNAMSIZ);
+  strncpy(ifra.ifra_name, dev_name + 5, IFNAMSIZ);
 
   s = socket(AF_INET, SOCK_DGRAM, 0);
   if (s < 0) {
@@ -143,19 +145,19 @@
   /*
    *  Set interface address
    */
-  sin = (struct sockaddr_in *)&(ifra.ifra_addr);
-  bcopy(ouraddr, sin, sizeof(struct sockaddr_in));
-  sin->sin_len = sizeof(*sin);
+  in = (struct sockaddr_in *)&(ifra.ifra_addr);
+  bcopy(ouraddr, in, sizeof(struct sockaddr_in));
+  in->sin_len = sizeof(*in);
 
   /*
    *  Set destination address
    */
-  sin = (struct sockaddr_in *)&(ifra.ifra_broadaddr);
-  if(Set_address(theiraddr,sin)) {
+  in = (struct sockaddr_in *)&(ifra.ifra_broadaddr);
+  if(Set_address(theiraddr,in)) {
     syslog(LOG_ERR,"bad destination address: %s",theiraddr);
     goto stunc_return;
   }
-  sin->sin_len = sizeof(*sin);
+  in->sin_len = sizeof(*in);
 
   if (ioctl(s, SIOCAIFADDR, &ifra) < 0) {
     syslog(LOG_ERR,"can't set interface address - %m");
@@ -183,7 +185,8 @@
   return(1);
 }
 
-void Finish(int signum)
+static void
+Finish(int signum)
 {
   int s;
 
@@ -232,7 +235,7 @@
 {
   int  c, len, ipoff;
 
-  char *devname = NULL;
+  char *dev_name = NULL;
   char *point_to = NULL;
   char *to_point = NULL;
   char *target;
@@ -259,7 +262,7 @@
       point_to = optarg;
       break;
     case 't':
-      devname = optarg;
+      dev_name = optarg;
       break;
     case 'p':
       protocol = optarg;
@@ -269,7 +272,7 @@
   argc -= optind;
   argv += optind;
 
-  if (argc != 1 || (devname == NULL) ||
+  if (argc != 1 || (dev_name == NULL) ||
       (point_to == NULL) || (to_point == NULL)) {
     usage();
   }
@@ -289,7 +292,7 @@
     exit(2);
   }
 
-  if(tun_open(devname, &t_laddr, to_point)) {
+  if(tun_open(dev_name, &t_laddr, to_point)) {
     closelog();
     exit(3);
   }




More information about the Submit mailing list