473,609 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
Hi,

Below is the raw socket program for sending routing header in ipv6 domain. My source address is fe80::21d:9ff:f e17:58c7 and destination address is fe80::21d:9ff:f e17: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("\nClien t: 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(soc k_fd, IPPROTO_IPV6, IPV6_RECVRTHDR, &on, sizeof(on)) < 0)
{
printf("\nClien t: RTHDR option set failed\n");
return;
}

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

daddr->sin6_family = AF_INET6;

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

daddr->sin6_port = htons(IPPROTO_I PV6);

/* Our Source Address is fe80::21d:9ff:f e17: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_ifin dex = 2; /* Interface Id */


/* Fill the Routing Header in ancillary data */
rthlen = inet6_rth_space (IPV6_RTHDR_TYP E_0, 1); //return #bytes required for Routing header
cmsglen = CMSG_SPACE(rthl en);
printf("\nClien t: rthlen is %d\n", rthlen);
cmsg = malloc(cmsglen) ;
if (cmsg == NULL)
{
printf("\nClien t: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_control len = 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("\nClien t: Routing Header Init failed\n");
return;
}

inet6_rth_add(r thp, &daddr->sin6_addr);

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

rthp = NULL;
if (ret < 0)
{
printf("\nClien t: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 3268

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

Similar topics

0
1405
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 web service. For example, the router get the request from a client checks for the type of header (WSE 2.0 content-based routing QuickStart Sample)
1
17032
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 control in my aspx page with two image buttons, one for an edit command, another a delete command. Here is a cut down code fragment. ...
0
303
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 masterpage. In the header of the masterpage, there is a text box with a search button. This button adds the value of the text box to the session state and then forwards the user to the search page. The search page inserts this value into the text...
2
2169
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. -------------------------------------------------------------------------------- Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/in configuration or <%@ Page EnableEventValidation="true"...
1
4925
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 the service manually using Installutil.exe utility. Unfortunately I am getting an error very early on, during the Installation phase which has left me totally stumped as I don't know how to go about fixing this.
0
11579
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 Security, but I'll start with something short and simple This code was written in Access 2003 but should be valid in Access 2000 By default, when you start a new module, either in a form or report, or a global module, Access does not declare Option...
25
62490
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 Files\Internet Explorer\Iexplore.exe http://www.google.ca", vbMaximizedFocus) End Sub i have a program thats been on my desktop for about a month now that uses these 3 lines of code(supposed to be 3 lines but it doesnt quite fit) and its been...
1
1465
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 tell me wha could possibly have gone wrong because I was not able to figure out anything. 348 c 7160 _cygtls::handle_exceptions: Error while dumping state (probably corrupted stack) Segmentation fault (core dumped) #include...
4
6302
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 Notice: Undefined index: args in /home/mattehz/public_html/acssr/trunk/inc_error.php on line 92 Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_error.php on line 92
0
8145
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8095
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8588
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8410
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6068
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5526
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4037
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2541
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.