0

I am trying to send u_char *packet (format of specific protocol) over local multicast (IPv6).

These are my steps I have already done:

  • Getting interface index via if_nametoindex(interface.c_str()), where interface.c_str() is string with name of interface
  • Getting IPv6 address of interface with struct ifaddrs *ifc and getifaddrs(&ifc), where I iterate through ifc, compare ifc->ifa_name with interface.c_str() and checking IPv6 address with IN6_IS_ADDR_LINKLOCAL(...)
  • Setting socket with socket(AF_INET6, SOCK_DGRAM, 0), setting socket option SO_REUSEADDR to 1, IPV6_MULTICAST_HOPS to 255 and IPV6_MULTICAST_IF to index of interface
  • Setting struct sockaddr_in6 like:

    struct sockaddr_in6 sa;
    bzero(&sa, sizeof(sa));
    sa.sin6_family = AF_INET6;
    sa.sin6_port = htons(521); //Port RIPng
    sa.sin6_scope_id = interfaceIndex;
    sa.sin6_addr = in6addr_any;
    
  • Binding socket with bind(sock, (struct sockaddr*)&sa, sizeof(sa))

  • Sending with sendto(sock, packet,sizeof(packet) 0, (struct sockaddr*)&sa, sizeof(sa))

After this, I am trying to listen using wireshark, but no packet of same protocol name is detected.

Where am I doing mistake?

user207421
  • 305,947
  • 44
  • 307
  • 483
Brykyz
  • 587
  • 4
  • 30
  • 1
    You need to `sendto()` a specific [multicast address](https://en.wikipedia.org/wiki/Multicast_address), and of course the receiver(s) need to join the multicast group using `setsockopt(s, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, ...)`. – TypeIA Nov 14 '18 at 22:14
  • @TypeIA There is no client/server in this application – Brykyz Nov 14 '18 at 22:22
  • 1
    I didn't say client or server, but I did say receiver, and in multicast there is always a sender and zero or more receivers. The routing association between the sender and receiver(s) is made via multicast addresses, to which the sender sends and the receivers associate using a socket option. – TypeIA Nov 14 '18 at 22:23

0 Answers0