(usagi-users 03541) IPv6 router alert option on RAW icmpv6 socket ?

hoerdt Mickael <[email protected]>
Newsgroups gmane.linux.ipv6.usagi.users
Message-ID <[email protected]>
Hi,

I'm trying to send messages over an ICMPv6 raw socket, and adding a 
router alert
option inside them. Attached is the program to do that. I don't 
understand what is
incorrect in this code, because RA option isn't added to the message 
when looking
on the wire with tcpdump...

Thanks,

Hoerdt Mickaël
test_ra.c (text/x-csrc, 1.4 KB)
#include <stdlib.h>
#include <stdio.h>
#include <netinet/icmp6.h>
#include <sys/socket.h>


#define MLD2_ALL_MCR_INIT { { { 0xff,0x02,0,0,0,0,0,0,0,0,0,0,0,0,0,0x16 } } }
static struct sockaddr_in6 dst_all_mldv2_routers = {AF_INET6,0,0,MLD2_ALL_MCR_INIT,0};

struct ip6_rta {
    uint8_t type;
    uint8_t length;
    uint16_t value;
} __attribute__ ((packed));

int main(int argc,char *argv[])
{
	int sockfd;
	char buffer[8]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
	struct msghdr sndmh;
	struct iovec sndiov[2];
	struct  ip6_rta rta;
	struct cmsghdr *cmsgp;

    	sndiov[0].iov_base = (caddr_t)buffer;
	sndiov[0].iov_len=8;
	sndmh.msg_name = (caddr_t)&dst_all_mldv2_routers;
        sndmh.msg_namelen = sizeof(struct sockaddr_in6);
        sndmh.msg_iov = sndiov;
        sndmh.msg_iovlen = 1;
	sndmh.msg_control = malloc(inet6_option_space(sizeof(struct ip6_rta)));

	rta.type = 5;
        rta.length = sizeof(rta.value);
        rta.value = 0;
	
	
	if((sockfd = socket (PF_INET6, SOCK_RAW, IPPROTO_ICMPV6))<0) {
	       perror("sockfd socket creation");
               exit(-1);
        }


        if((inet6_option_init(sndmh.msg_control, &cmsgp, IPV6_HOPOPTS))!=0)
            printf("inet6_option_init error\n");
        if((inet6_option_append(cmsgp, (uint8_t *)&rta, 1, 0))!=0)
            printf("inet6_option_append error\n");
      	sndmh.msg_controllen = cmsgp->cmsg_len; 
	
	
	if(sendmsg(sockfd,&sndmh,0)<0)
            perror("sendmsg");


}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.