LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 09-14-2006, 07:16 AM   #1
ksuresh_cse@yahoo.co
LQ Newbie
 
Registered: Sep 2006
Posts: 1

Rep: Reputation: 0
Question sendmsg : Invalid Argument


Hi,

I m new to Linux and socket programming in IPv6,please check out the code. I know the error which is w.r.t Memory allocation. The code snippet is:

int main()
{
sockfd = socket(PF_INET6,SOCK_RAW,IPPROTO_RAW);
struct sockaddr_in6 sin;
********
// Inserted the IPv6 address along with the other options in the above structure

setsockopt(sockfd,IPPROTO_IPV6,IPV6_PKTINFO,&one,s izeof(int))
struct in6_pktinfo ip;
memset(&ip,0,sizeof(ip));
memcpy((char *)ip.ipi6_addr.s6_addr16,(char *)sin.sin6_addr.s6_addr16,sizeof(struct
in6_addr));
ip.ipi6_ifindex = 0;//htonl(if_nametoindex("eth0"));
struct iovec io[1];
struct msghdr hdr;

memset(&io,0,sizeof(struct iovec));
memset(&hdr,0,sizeof(hdr) );

#if 1
struct cmsghdr *cmsg;
int cmsglen = CMSG_SPACE(sizeof(ip));
cmsg = malloc(cmsglen);
if(cmsg == NULL)
{
printf("CMSG ALLOC Failed");
return -ENOMEM;
}
memset(cmsg,0,cmsglen);

hdr.msg_control = cmsg;
hdr.msg_controllen =CMSG_SPACE( cmsglen);
#endif

io[0].iov_base =(char *) msg;
io[0].iov_len = sizeof(msg);

hdr.msg_name = (void *)&sin;
hdr.msg_namelen = sizeof(struct sockaddr_in6);
hdr.msg_iov = io;
hdr.msg_iovlen = 1;
hdr.msg_flags =0;

int kl;
while(1)
{
if ((kl = sendmsg(sockfd,&hdr,0)) < 0)
{
// close(sockfd);
printf("Client : Error in sendto() : %s \n",strerror(errno));
}
else
{

printf(" %d ",kl,strerror(errno));
printf(".");
}

fflush(stdout);
sleep(1);
}

return 0;
}

This is the code which when run is returning invalid argument error ,
So any help in this regard will be appreciated


regards,


Suresh K
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Invalid argument runtime error on sendmsg(). JohnHubert Linux - Networking 3 08-30-2010 09:44 AM
KDSKBENT: Invalid Argument tommytomato Linux - Newbie 6 08-27-2004 10:23 PM
Accept(): Invalid Argument bonhomme Programming 3 07-27-2004 03:37 PM
[ Invalid Argument on 'iptables' ] benleung Linux - Security 1 09-23-2003 12:25 AM
xawtv - invalid argument liguorir Linux - Software 0 06-17-2003 08:55 PM


All times are GMT -5. The time now is 03:53 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration