473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Invalid argument: error 22 while using sendmsg to routing header (ipv6)

Hi,

Below is the raw socket program for sending routing header in ipv6 domain. My source address is fe80::21d:9ff:fe17:58c7 and destination address is fe80::21d:9ff:fe17:5d0e in the below example. When i run this i am getting invalid argument with sendmsg, with error number 22. Could any one please help me out with this.

#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/ip6.h>
#include <errno.h>
#include <string.h>

void main()
{
int sock_fd;
int on = 1;
int offset = 4;
int ret = 0;

struct sockaddr_in6 *daddr;
struct in6_pktinfo pinfo;
struct msghdr msg;
struct cmsghdr *cmsg;
struct iovec *iovector;
socklen_t rthlen = 0;
int cmsglen;

sock_fd = socket(AF_INET6, SOCK_RAW, IPPROTO_IPV6);

if(sock_fd < 0)
{
printf("\nClient: Socket Creation Failed: Error %d\n", errno);
return;
}

iovector = (struct iovec*)calloc(1, sizeof(struct iovec));


/* Since for Mobility Header the checksum is located in offset 4, we need to
* set the offset to 4
*/
if (setsockopt(sock_fd, IPPROTO_IPV6, IPV6_RECVRTHDR, &on, sizeof(on)) < 0)
{
printf("\nClient: RTHDR option set failed\n");
return;
}

/* Our Destination Address is fe80::21d:9ff:fe17:5d0e eth0 interface
* i.e. fe80:0:0:0:021d:09ff:fe17:5d0e
*/
daddr = (struct sockaddr_in6*)calloc(1, sizeof(struct sockaddr_in6));

daddr->sin6_family = AF_INET6;

daddr->sin6_addr.s6_addr16[0] = 0xfe80;
daddr->sin6_addr.s6_addr16[1] = 0x0;
daddr->sin6_addr.s6_addr16[2] = 0x0;
daddr->sin6_addr.s6_addr16[3] = 0x0;
daddr->sin6_addr.s6_addr16[4] = 0x021d;
daddr->sin6_addr.s6_addr16[5] = 0x09ff;
daddr->sin6_addr.s6_addr16[6] = 0xfe17;
daddr->sin6_addr.s6_addr16[7] = 0x5d0e;

daddr->sin6_port = htons(IPPROTO_IPV6);

/* Our Source Address is fe80::21d:9ff:fe17:58c7 eth0 interface
* i.e. fe80:0:0:0:021d:09ff:fe17:58c7
*/
memset(&pinfo, 0, sizeof(struct in6_pktinfo));

pinfo.ipi6_addr.s6_addr16[0] = 0xfe80;
pinfo.ipi6_addr.s6_addr16[1] = 0x0;
pinfo.ipi6_addr.s6_addr16[2] = 0x0;
pinfo.ipi6_addr.s6_addr16[3] = 0x0;
pinfo.ipi6_addr.s6_addr16[4] = 0x021d;
pinfo.ipi6_addr.s6_addr16[5] = 0x09ff;
pinfo.ipi6_addr.s6_addr16[6] = 0xfe17;
pinfo.ipi6_addr.s6_addr16[7] = 0x58c7;
pinfo.ipi6_ifindex = 2; /* Interface Id */


/* Fill the Routing Header in ancillary data */
rthlen = inet6_rth_space(IPV6_RTHDR_TYPE_0, 1); //return #bytes required for Routing header
cmsglen = CMSG_SPACE(rthlen);
printf("\nClient: rthlen is %d\n", rthlen);
cmsg = malloc(cmsglen);
if (cmsg == NULL)
{
printf("\nClient:Ancillary Data memory allocation failed\n");
return;
}

memset(cmsg, 0, cmsglen);
memset(&msg, 0, sizeof(msg));

iovector->iov_base = malloc(10);
iovector->iov_len = 10;

strcpy(iovector->iov_base, "TEST-4-RH");

msg.msg_control = (void *)cmsg;
msg.msg_controllen = cmsglen;
msg.msg_iov = iovector;
msg.msg_iovlen = 1;
msg.msg_name = (void *)daddr;
msg.msg_namelen = sizeof(struct sockaddr_in6);

void *rthp;

cmsg = CMSG_FIRSTHDR(&msg);

cmsg->cmsg_len = CMSG_LEN(rthlen);
cmsg->cmsg_level = IPPROTO_IPV6;
cmsg->cmsg_type = IPV6_RTHDR;

rthp = CMSG_DATA(cmsg);
rthp = inet6_rth_init(rthp, rthlen, IPV6_RTHDR_TYPE_0, 1);

if(rthp == NULL)
{
printf("\nClient: Routing Header Init failed\n");
return;
}

inet6_rth_add(rthp, &daddr->sin6_addr);

ret = sendmsg(sock_fd, &msg, 0);

rthp = NULL;
if (ret < 0)
{
printf("\nClient:Send Message Failed: Error %d Ret %d\n", errno, ret);
free(iovector->iov_base);
free(iovector);
return;
}
}

Thanks in advance,
shekhar
Oct 31 '08 #1
0 3252

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Gururaj | last post by:
Hi Everyone, Can any one help me in acheiving the following There's a router which accepts all the requests from the clients and then routes the request based on the content to the appropriate...
1
by: Timbo | last post by:
Hi all, This is my first message here so i'll try and include all the information that will help you help me out, if possible. Basically I am using C# in ASP.NET 2.0 and have a Repeater...
0
by: Matt MacDonald | last post by:
Hi all, I know this question has been posted all over the place, but it doesn't look like there are any definative answers, especially for the scenario I am using. I have a site with a...
2
by: Nathan Sokalski | last post by:
I have a DataList in which the ItemTemplate contains two Button controls that use EventBubbling. When I click either of them I receive the following error: Server Error in '/' Application....
1
by: eoinmoon | last post by:
Hi all, New to C# and VS 5 and .NET. I have attempted to write a service via various examples and after several failed attempts to write an installer via the VS 5 wizards,etc I tried to install...
0
by: Lysander | last post by:
Thought I would give something back with a few articles. This article is a bit of code to add error handling. When I have time, I want to write articles on multilingual databases, and Access...
25
by: dennijr | last post by:
ok, shell always used to be easy for me, now its starting to get annoying cause i dont know wats wrong heres the simplist code possible: Private Sub IExplorer_Click() a = Shell("C:\Program...
1
by: dranz3r | last post by:
I wrote this c program to send a struct from the client to a server which has the same struct initialized in it. I used gcc feature of cygwin to compile it and I got the following error. Can anyone...
4
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.