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

(usagi-users 02251) Re: Raw socket + IPv6 = sendto invalid argume nt



From the kernel source code, it seems that when you use raw ipv6 socket, you
have to set  

dest.sin6_port = htons(IPPROTO_RAW);


Does this works for you?


Michael
Not speaking for Intel,   options are my own.



-----Original Message-----
From: Daniel Martinez [mailto:djmm1@xxxxxxxxx]
Sent: 2003?3?6? 21:06
To: usagi-users@xxxxxxxxxxxxxx
Subject: (usagi-users 02249) Raw socket + IPv6 = sendto invalid argument


Hello,

I'm trying to send data over an IPv6 raw socket, but I keep getting an
"invalid argument" error in the sendto call. I'm not able to find the cause
of this error, so I'd greatly thank any help.

Here is a paste of the code:

--- BEGIN CODE ---
#include <linux/if_ether.h>
#include <netinet/ip6.h>
#include <stdio.h>
#include <errno.h>
#include <sys/socket.h>

#define BUFSIZE 100

unsigned char buf[BUFSIZE];

int main(void)
{
 int s;
 int i;
 struct sockaddr_in6 dest;

 dest.sin6_family = AF_INET6;
 // Destination is loopback
 for(i=0;i<7;i++) dest.sin6_addr.s6_addr16[i]=0;
 dest.sin6_addr.s6_addr16[7]=htons(1);
 dest.sin6_flowinfo = 0;
 dest.sin6_scope_id = 0;
 dest.sin6_port = htons(9999);

 s = socket(PF_INET6, SOCK_RAW, IPPROTO_RAW);
 if(s<0)
 {
  perror("socket()");
  return 1;
 }
 if(sendto(s, buf, BUFSIZE, 0, (struct sockaddr*)&dest, sizeof(dest)) == -1)
 {
  perror("sendto()");
  close(s);
  return 1;
 }
 close(s);
 return 0;
}
--- END CODE ---