我正在尝试使用原始套接字将路由器通告数据包发送到多播地址ff02 :: 1.原始套接字使用rndis0网络接口成功绑定
当我使用send()调用发送RA消息头时,发送消息失败,错误代码为99,无法分配请求的地址。 我以in6_Addr格式
分配了msghdr.msg_name = ff02 :: 11地址发送失败99的可能原因是什么? 感谢
答案 0 :(得分:1)
the code which i am using to send router advertisement packet from android mobile to tethered PC with ipv6 link local address.
The interface used to send in device side is rndis0 ,tethered interface
int sock;
if((sock = socket(AF_INET6,SOCK_RAW,IPPROTO_ICMP6)) <0)
{//error
}
struct ifreq Interface1;
memset(&Interface1, 0, sizeof(Interface1));
strncpy(Interface1.ifr_ifrn.ifrn_name, "rndiso", IFNAMSIZ);
if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, &Interface1, sizeof(Interface1)) < 0) { close(s); }
struct msghdr msg;
struct in6_addr address;
sockaddr_in6 addr;
addr.sin6_family = AF_INET6;
addr.sin6_port = htons(58) //58 is icmpv6 port no
inet_pton(AF_INET6,"ff80::2001:db8",&address);
addr.sin6_addr = address;
msg.msg_name = (caddr_t)addr
msg.msg_namelen = sizeof(addr)
struct iovec iv;
iv.iov_base = buffer ///buffer is router advertisement packet
iv.iov_len = sizeof(buffer)
msg.msg_iov = iv;
msg.msg_iovlen = 1;
msg.msg_control =NULL;
msg.msg_controllen = 0;
if(sendmsg(sock,&msg,0)
{
perror(error is :")
}
result : error is **cannot assign requested address**