Hello,
I believe this is the best place to ask questions on ipv6 raw socket
problem.
Problem:
I am opening am raw ipv6 socket. Then trying to send and receive data
using it. But I get invalid argument(EINVAL) from both sendmsg()
and recvfrom() system call when trying to send data. Why is this happening?
Q: What is wrong in following code?
Q: Why the error is Invalid Argument? This same code executes on
Solaris IPv6 machine with little change.
Q: Kernel missing some module????
How to know if my machine has raw IPv6 support or raw6 module in
the kernel is installed or not. I see
raw6 module is there in /proc/net dir.
Pls help me out.
Thanks.
Arif.
-----------------------oOo--------------------------Code
-----------------------oOo--------------------------
int enable=1;
struct sockaddr_in6 srcAddr6;
size=sizeof(sockaddr_in6);
.......
sd=socket(AF_INET6, SOCK_RAW, IPPROTO_RAW); /*ipv6 raw socket*/
/* set socket options */
ioctl(sd,(S32)FIONBIO, &enable); /* make socket NonBlocking */
setsockopt(sd, level, SO_BSDCOMPAT,&enable, sizeof(enable));
setsockopt(sd, level, SO_REUSEADDR,(char*)&enable,sizeof(enable));
/* binding */
cmMemset((U8*)&srcAddr6, 0, sizeof(srcAddr6));
srcAddr6.sin6_family = AF_INET6;
srcAddr6.sin6_port = CM_INET_HTON_U16(port);
COPY_IPV6ADDR(&srcAddr6.sin6_addr,&in6addr_loopback); /*loopback used*/
sizeOfAddr = sizeof(struct sockaddr_in6);
sockAddrPtr = (sockAddr *)&srcAddr6;
bind(sd, sockAddrPtr, sizeOfAddr);
getsockname(sd, &lclSockAddr, (int*)&size);
sending data:
struct sockaddr_in6 remAddr6;
int sizeOfAddr;
struct msghdr msg;
char buffer [1][100];
struct iovec io[1];
remAddr6.sin6_family = AF_INET6;
remAddr6.sin6_port = CM_INET_HTON_U16(12447);
COPY_IPV6ADDR(&remAddr6.sin6_addr,
&in6addr_loopback); /* macro */
sizeOfAddr = sizeof(remAddr6);
cmMemset(&msg, 0, sizeof(msg)); /*fill up msg with all 0*/
msg.msg_name = (void*)&remAddr6;
msg.msg_namelen = sizeOfAddr;
io[0].iov_base = buffer[0];
sprintf(buffer[0]," This is a test\n");
io[0].iov_len = strlen(buffer[0]);
msg.msg_iov = io;
msg.msg_iovlen = 1;
msg.msg_control = NULL;
msg.msg_controllen = 0;
msg.msg_flags = 0;
ret = sendmsg(sd, &msg, 0); ===> returns (-1):EINVAL
or
recvfrom(.......) ===> returns (-1): EINVAL too.
|