src/devices/tap-bridge/tap-creator.cc
changeset 4353 596eb8034443
parent 4290 af8a40d5c2cb
equal deleted inserted replaced
4352:6095f91e6a64 4353:596eb8034443
   136 	}
   136 	}
   137       str++;
   137       str++;
   138     }
   138     }
   139 }
   139 }
   140 
   140 
   141 static void
   141 static sockaddr
   142 SetInetAddress (sockaddr *ad, uint32_t networkOrder)
   142 CreateInetAddress (uint32_t networkOrder)
   143 {
   143 {
   144   struct sockaddr_in *sin = (struct sockaddr_in*)ad;
   144   union {
   145   sin->sin_family = AF_INET;
   145     struct sockaddr any_socket;
   146   sin->sin_port = 0; // unused
   146     struct sockaddr_in si;
   147   sin->sin_addr.s_addr = htonl (networkOrder);
   147   } s;
       
   148   s.si.sin_family = AF_INET;
       
   149   s.si.sin_port = 0; // unused
       
   150   s.si.sin_addr.s_addr = htonl (networkOrder);
       
   151   return s.any_socket;
   148 }
   152 }
   149 
   153 
   150   static void
   154   static void
   151 SendSocket (const char *path, int fd)
   155 SendSocket (const char *path, int fd)
   152 {
   156 {
   328   LOG ("Device is up");
   332   LOG ("Device is up");
   329 
   333 
   330   //
   334   //
   331   // Set the IP address of the new interface/device.
   335   // Set the IP address of the new interface/device.
   332   //
   336   //
   333   SetInetAddress (&ifr.ifr_addr, AsciiToIpv4 (ip));
   337   ifr.ifr_addr = CreateInetAddress (AsciiToIpv4 (ip));
   334   status = ioctl (fd, SIOCSIFADDR, &ifr);
   338   status = ioctl (fd, SIOCSIFADDR, &ifr);
   335   ABORT_IF (status == -1, "Could not set IP address", true);
   339   ABORT_IF (status == -1, "Could not set IP address", true);
   336   LOG ("Set device IP address to " << ip);
   340   LOG ("Set device IP address to " << ip);
   337 
   341 
   338   //
   342   //
   339   // Set the net mask of the new interface/device
   343   // Set the net mask of the new interface/device
   340   //
   344   //
   341   SetInetAddress (&ifr.ifr_netmask, AsciiToIpv4 (netmask));
   345   ifr.ifr_netmask = CreateInetAddress (AsciiToIpv4 (netmask));
   342   status = ioctl (fd, SIOCSIFNETMASK, &ifr);
   346   status = ioctl (fd, SIOCSIFNETMASK, &ifr);
   343   ABORT_IF (status == -1, "Could not set net mask", true);
   347   ABORT_IF (status == -1, "Could not set net mask", true);
   344   LOG ("Set device Net Mask to " << netmask);
   348   LOG ("Set device Net Mask to " << netmask);
   345 
   349 
   346   return tap;
   350   return tap;