LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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
  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



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Accept(): Invalid Argument bonhomme Programming 6 07-14-2012 10:12 PM
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
[ 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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:43 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration