title: Error “No such device” in call setsockopt IPV6_ADD_MEMBERSHIP
body: <p>Related: <a href="https://stackoverflow.com/questions/3187919/error-no-such-device-in-call-setsockopt">Error &quot;No such device&quot; in call setsockopt</a></p>
  
  <p>while stracing one of a unit test process (I am not the author of the unit test), I am encountering </p>
  
  <pre><code>socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP) = 8
  setsockopt(8, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
  setsockopt(8, SOL_IPV6, IPV6_ADD_MEMBERSHIP, "\377\2\0\0\0\0\0\0\0\0\0\0\0\0\0\373\2\0\0\0", 20) = -1 ENODEV (No such device)
  close(8)                                = 0
  </code></pre>
  
  <p>On the related question, it is susepcting that MULTICAST is not enabled on the machine</p>
  
  <p>However, I believe it is enabled in my environment as I see MULTICAST</p>
  
  <pre><code>eth0      Link encap:Ethernet  HWaddr 02:42:AC:12:00:02  
            inet addr:172.18.0.2  Bcast:172.18.255.255  Mask:255.255.0.0
            UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
            RX packets:15 errors:0 dropped:0 overruns:0 frame:0
            TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:0 
            RX bytes:1518 (1.4 KiB)  TX bytes:0 (0.0 b)
  
  eth1      Link encap:Ethernet  HWaddr 02:42:0A:3C:73:A9  
            inet addr:10.60.115.169  Bcast:10.60.115.255  Mask:255.255.254.0
            inet6 addr: fd20:8b1e:b255:8136:42:aff:fe3c:73a9/64 Scope:Global
            inet6 addr: 2002:3984:3989::2/80 Scope:Global
            inet6 addr: fe80::42:aff:fe3c:73a9/64 Scope:Link
            UP BROADCAST RUNNING MULTICAST  MTU:9000  Metric:1
            RX packets:2797166513 errors:0 dropped:5 overruns:0 frame:0
            TX packets:1847378326 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:0 
            RX bytes:5442226175566 (4.9 TiB)  TX bytes:4392851979876 (3.9 TiB)
  
  lo        Link encap:Local Loopback  
            inet addr:127.0.0.1  Mask:255.0.0.0
            inet6 addr: ::1/128 Scope:Host
            UP LOOPBACK RUNNING  MTU:65536  Metric:1
            RX packets:861782 errors:0 dropped:0 overruns:0 frame:0
            TX packets:861782 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:1 
            RX bytes:363667068 (346.8 MiB)  TX bytes:363667068 (346.8 MiB)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>$ netstat -g
  IPv6/IPv4 Group Memberships
  Interface       RefCnt Group
  --------------- ------ ---------------------
  lo              1      all-systems.mcast.net
  eth0            1      all-systems.mcast.net
  eth1            1      all-systems.mcast.net
  lo              1      ff02::1
  lo              1      ff01::1
  eth0            1      ff02::1
  eth0            1      ff01::1
  eth1            1      ff02::202
  eth1            2      ff02::1:ff3c:73a9
  eth1            1      ff02::1:ff00:2
  eth1            1      ff02::1
  eth1            1      ff01::1
  </code></pre>
  
  <p>Any idea why I am getting "No such device" in call setsockopt?</p>
  
  <p>am i missing some options on /etc/sysctl.conf?
  I am running on RHEL7.4</p>
  
  <p>I believe the code i am seeing it from</p>
  
  <pre><code>static int
  create_ipv6_listener_socket(ifi_info* ifi)
  {
      struct ipv6_mreq imr6;
      int err = 0;
      static const int kOn = 1;
      int skt = -1;
  
      std::string addr_str = sock_addr_to_string(ifi-&gt;ifi_ipv6_addr);
      TLOG_INFO(plogger, "Creating listener socket on addr %s", addr_str.c_str());
  
      skt = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
      if (skt &lt; 0) {
          TLOG_ERROR(plogger,
                     "Failed to create listener socket on addr %s: %d",
                     addr_str.c_str(),
                     errno);
          return -1;
      }
  
      err = setsockopt(skt, SOL_SOCKET, SO_REUSEADDR, &amp;kOn, sizeof(kOn));
      if (err &lt; 0) {
          TLOG_ERROR(plogger,
                     "For listener socket on %s, failed to set SO_REUSEADDR: %d",
                     addr_str.c_str(),
                     errno);
          close(skt);
          return -1;
      }
  
      imr6.ipv6mr_interface = ifi-&gt;ifi_index;
      err = inet_pton(AF_INET6, "FF02::FB", &amp;imr6.ipv6mr_multiaddr);
      if (err &lt; 1) { 
          TLOG_ERROR(plogger,
                     "For listener socket on %s, failed to assign dns-sd "
                     "multicast address: %d",
                     addr_str.c_str(),
                     errno);
          close(skt);
          return -1;
      }    
  
      err = setsockopt(skt, IPPROTO_IPV6, IPV6_JOIN_GROUP, &amp;imr6, sizeof(imr6));
      if (err &lt; 0) { 
          TLOG_ERROR(
              plogger,
              "For listener socket on %s, failed to join multicast group: %d",
              addr_str.c_str(),
              errno);
          close(skt);
          return -1;
      }  
  
  
  static int
  create_listener_socket(ifi_info* ifi)
  {
      if (ifi-&gt;ifi_family == AF_INET) {
          return create_ipv4_listener_socket(ifi);
      } else if (ifi-&gt;ifi_family == AF_INET6) {
          return create_ipv6_listener_socket(ifi);
      } else {
          assert(false);
      }
  
      return -1;
  }
  
  static void
  create_sockets()
  {
      int skt = -1;
      std::vector&lt;struct ifi_info*&gt; interfaces;
  
      ifi = (struct ifi_info*)calloc(1, sizeof(struct ifi_info));
      assert(ifi);
      strcpy(ifi-&gt;ifi_name, "fake_ipv6_ifi_info");
      ifi-&gt;ifi_family = AF_INET6;
      ifi-&gt;ifi_index = 2;
      interfaces.push_back(ifi);
  
      for (uint32_t ii = 0; ii &lt; interfaces.size(); ++ii) {
          struct ifi_info* ifi = interfaces[ii];
  
          while ((skt = create_listener_socket(ifi)) == -1) {
              TLOG_ERROR(plogger,
                     "Failed to create a listener socket for interface %s; "
                     "will try again in 5 seconds",
                     ifi-&gt;ifi_name);
              sleep(5);
          }
          listener_sockets.push_back(skt);
  </code></pre>
  
  <p>I am getting error "For listener socket on INADDR_ANY, failed to join multicast group: 19"</p>