[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



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
#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");


}