fixed uninitialized variables when ioctl() on the given interfaces
authorEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Fri, 21 Nov 2003 16:01:09 +0000 (16:01 +0000)
committerEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Fri, 21 Nov 2003 16:01:09 +0000 (16:01 +0000)
fails (thanks to Herbert Poetzl)

git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/branches/SYSCALL_SWITCH@439 94cd875c-1c1d-0410-91d2-eb244daf1a30

util-vserver/src/ifspec.c

index cebe4d0..7d665d2 100644 (file)
@@ -104,7 +104,7 @@ int ifconfig_print (
                struct {
                        unsigned long addr;
                        unsigned long mask;
-               } solved;
+               } solved = {0,0};
                if (addrstr != NULL && addrstr[0] != '\0'){
                        printf ("ADDR=%s\n",addrstr);
                        solved.addr = ip_cnv (addrstr);
@@ -119,6 +119,10 @@ int ifconfig_print (
                        solved.addr = addr;
                        ret = 0;
                }
+               else {
+                 perror("ioctl(SIOCGIFADDR)");
+               }
+               
                if (maskstr != NULL && maskstr[0] != '\0'){
                        printf ("NETMASK=%s\n",maskstr);
                        solved.mask = ip_cnv (maskstr);
@@ -133,6 +137,10 @@ int ifconfig_print (
                        solved.mask = addr;
                        ret = 0;
                }
+               else {
+                 perror("ioctl(SIOCGIFNETMASK)");
+               }
+               
                if (bcaststr != NULL && bcaststr[0] != '\0'){
                        printf ("BCAST=%s\n",bcaststr);
                }else if (ifconfig_ioctl(skfd,ifname,SIOCGIFBRDADDR, &ifr) >= 0){
@@ -144,7 +152,7 @@ int ifconfig_print (
                                ,(addr>>8)&0xff
                                ,addr&0xff);
                        ret = 0;
-               }else{
+               }else if (solved.addr!=0 && solved.mask!=0) {
                        // Can't get it from the kernel, compute it from the IP
                        // and the netmask
                        unsigned long addr = (solved.addr & solved.mask)