added Vector_zeroEnd() function
[util-vserver.git] / util-vserver / src / chbind.c
index 21981ce..285fe1c 100644 (file)
@@ -38,6 +38,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
+#define ENSC_WRAPPERS_PREFIX   "chbind: "
 #define ENSC_WRAPPERS_IO       1
 #define ENSC_WRAPPERS_UNISTD   1
 #include "wrappers.h"
@@ -238,10 +239,11 @@ readBcast(char const *str, uint32_t *bcast)
 
 int main (int argc, char *argv[])
 {
-  bool                         is_silent = false;
-  struct vc_ip_mask_pair       ips[16];
+  size_t const                 nb_ipv4root = vc_get_nb_ipv4root();
+  bool                         is_silent   = false;
+  struct vc_ip_mask_pair       ips[nb_ipv4root];
   size_t                       nbaddrs = 0;
-  uint32_t                     bcast = 0xffffffff;
+  uint32_t                     bcast   = 0xffffffff;
   
   while (1) {
     int                c = getopt_long(argc, argv, "+", CMDLINE_OPTIONS, 0);
@@ -253,7 +255,7 @@ int main (int argc, char *argv[])
       case CMD_SILENT          :  is_silent = true; break;
       case CMD_BCAST           :  readBcast(optarg, &bcast); break;
       case CMD_IP              :
-       if (nbaddrs>=16) {
+       if (nbaddrs>=nb_ipv4root) {
          WRITE_MSG(2, "Too many IP numbers, max 16\n");
          exit(wrapper_exit_code);
        }
@@ -276,7 +278,7 @@ int main (int argc, char *argv[])
   
 
   if (vc_set_ipv4root(bcast,nbaddrs,ips)!=0) {
-    perror("vc_set_ipv4root()");
+    perror("chbind: vc_set_ipv4root()");
     exit(wrapper_exit_code);
   }
 
@@ -315,8 +317,12 @@ void test()
 
   readIP("localhost", &ip, &bcast);
   assert(ip.ip==ntohl(0x7f000001) && ip.mask==ntohl(0xffffff00) && bcast==0);
-  
-  readIP("lo", &ip, &bcast);
-  assert(ip.ip==ntohl(0x7f000001) && ip.mask==ntohl(0xff000000) && bcast==ntohl(0x7fffffff));
+
+#if 0
+  if (ifconfig_getaddr("lo", &tmp, &tmp, &tmp)!=-1) {
+    readIP("lo", &ip, &bcast);
+    assert(ip.ip==ntohl(0x7f000001) && ip.mask==ntohl(0xff000000) && bcast==ntohl(0x7fffffff));
+  }
+#endif
 }
 #endif