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())
, whereinterface.c_str()
is string with name of interface - Getting IPv6 address of interface with
struct ifaddrs *ifc
andgetifaddrs(&ifc)
, where I iterate throughifc
, compareifc->ifa_name
withinterface.c_str()
and checking IPv6 address withIN6_IS_ADDR_LINKLOCAL(...)
- Setting socket with
socket(AF_INET6, SOCK_DGRAM, 0)
, setting socket optionSO_REUSEADDR
to 1,IPV6_MULTICAST_HOPS
to 255 andIPV6_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?