title: add and delete virtual IP Linux c++
body: <p>I tried to figure out how to add and delete virtual ip in the same way I do with "ip addr add @ip dev @interface" and "ip addr del @ip dev @interface".</p>
  
  <p>I succeed in changing the ip thanks to this code :</p>
  
  <pre><code>#include &lt;sys/ioctl.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;net/if.h&gt;
  #include &lt;string.h&gt;
  
  int main(int argc, const char *argv[]) 
  {
      struct ifreq ifr;
      const char * name = "eth1";
      int fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
      struct sockaddr_in* addr = (struct sockaddr_in*)&amp;ifr.ifr_addr;
  
      strncpy(ifr.ifr_name, name, IFNAMSIZ);
  
      ifr.ifr_addr.sa_family = AF_INET;
      inet_pton(AF_INET, "1.1.1.1", &amp;addr-&gt;sin_addr);
  
      ioctl(fd, SIOCSIFADDR, &amp;ifr);
  
      inet_pton(AF_INET, "255.255.255.0", &amp;addr-&gt;sin_addr);
      ioctl(fd, SIOCSIFNETMASK, &amp;ifr);
  
      ioctl(fd, SIOCGIFFLAGS, &amp;ifr);
      strncpy(ifr.ifr_name, name, IFNAMSIZ);
      ifr.ifr_flags |= (IFF_UP | IFF_RUNNING);
  
      ioctl(fd, SIOCSIFFLAGS, &amp;ifr);
  
      return 0;
  }
  </code></pre>
  
  <p>But I didn't manage to add virual ip. Does any one know how it works ?</p>
  
  <p>Thanks</p>