Hi,
I have a short function which is trying to send an
icmp message out a raw ipv6 socket.
when I run the following code I get "wrote -1"...
i.e. sendto() is returning an error. Can someone
please tell me what I'm doing wrong?
-----
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <netinet/icmp6.h>
int main() {
int sockfd,len,out;
struct sockaddr_in6 myDst;
struct icmp6_hdr *hdr;
char sendbuff[1500]="abcdefghijklmnop";
out=0;
sockfd=socket(AF_INET6,SOCK_RAW,IPPROTO_ICMPV6);
if( !inet_pton(AF_INET6,'fed0:10:100::1",&myDst) )
printf("bad address\n"
hdr=(struct icmp6_hdr *)sendbuff;
hdr->icmp6_type=ND_ROUTER_ADVERT; //don't care about type... just want to send!
hdr->icmp6_code=0;
hdr->icmp6_cksum=0;
hdr->icmp6_seq=htons(6); //dummy val
hdr->icmp6_id=htons(8);//dummy val
out=sendto(sockfd, (char *) sendbuff, 8, 0, (struct sockaddr *) &myDst, sizeof(myDst));
printf("wrote %d\n",out);
return 1;
}
-----
thank-you so much!!
I have a short function which is trying to send an
icmp message out a raw ipv6 socket.
when I run the following code I get "wrote -1"...
i.e. sendto() is returning an error. Can someone
please tell me what I'm doing wrong?
-----
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <netinet/icmp6.h>
int main() {
int sockfd,len,out;
struct sockaddr_in6 myDst;
struct icmp6_hdr *hdr;
char sendbuff[1500]="abcdefghijklmnop";
out=0;
sockfd=socket(AF_INET6,SOCK_RAW,IPPROTO_ICMPV6);
if( !inet_pton(AF_INET6,'fed0:10:100::1",&myDst) )
printf("bad address\n"
hdr=(struct icmp6_hdr *)sendbuff;
hdr->icmp6_type=ND_ROUTER_ADVERT; //don't care about type... just want to send!
hdr->icmp6_code=0;
hdr->icmp6_cksum=0;
hdr->icmp6_seq=htons(6); //dummy val
hdr->icmp6_id=htons(8);//dummy val
out=sendto(sockfd, (char *) sendbuff, 8, 0, (struct sockaddr *) &myDst, sizeof(myDst));
printf("wrote %d\n",out);
return 1;
}
-----
thank-you so much!!