LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Closed Thread
  Search this Thread
Old 09-10-2010, 08:07 PM   #1
gr1980
LQ Newbie
 
Registered: Sep 2010
Posts: 5

Rep: Reputation: 0
sendto failed -1 : Invalid argument


I'm not sure why the sndto() is failing. I am a newbie so any pointers would be great!


STATUS send_request(const packet_t * pkt)
{

int fd = -1; /* socket filedescriptor */
int result = 0; /* sendto status */
struct sockaddr_in sa; /* structure for handling internet addressing */

/* create UDP socket PF_PACKET for post 2.0 kernel */
fd = socket(PF_PACKET, SOCK_DGRAM, IPPROTO_UDP);
if (-1 == fd)
{
/* error case */
printf ("%s:%d socket failed %s", __FUNCTION__, __LINE__, strerror(errno) );
return FAILED;
}

/* setup sockaddr_in struct */
memset((char *) &sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_port = htons(SEND_PORT);
/* if (0 == inet_aton(SVR_IP, &sa.sin_addr))
{
// error case
printf ("%s:%d inet_aton failed", __FUNCTION__, __LINE__ );
if (-1 == (close(fd)))
{
printf ("%s:%d close failed %s", __FUNCTION__, __LINE__, strerror(errno) );
}
return FAILED;
}
*/

/* send packet */
printf ("%s:%d sendto fd:%d sizeof(packet_t):%d sizeof(pkt):%d", __FUNCTION__, __LINE__,fd, sizeof(packet_t), sizeof(pkt));

result = sendto(fd, pkt, sizeof(packet_t), 0, (struct sockaddr *)&sa, sizeof(sa));
if(-1 == result)
{
/* error case */
printf ("%s:%d sendto failed %d : %s", __FUNCTION__, __LINE__,result, strerror(errno) );
if (-1 == (close(fd)))
{
printf ("%s:%d close failed %s", __FUNCTION__, __LINE__, strerror(errno) );
}
return FAILED;
}
else if (sizeof(packet_t) == result)
{
/* success case */
printf ("%s:%d sendto successful", __FUNCTION__, __LINE__ );
if (-1 == (close(fd)))
{
printf ("%s:%d close failed %s", __FUNCTION__, __LINE__, strerror(errno) );
return FAILED;
}
}
else
{
/* catch all */
printf ("%s:%d sendto %d : %s", __FUNCTION__, __LINE__,result, strerror(errno) );
if (-1 == (close(fd)))
{
printf ("%s:%d close failed %s", __FUNCTION__, __LINE__, strerror(errno) );
}
return FAILED;
}

return SUCCESS;
}

Last edited by gr1980; 09-10-2010 at 08:08 PM.
 
Old 09-11-2010, 03:01 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.


http://www.linuxquestions.org/questi...gument-831489/


In this case we closed the original in favour of the more
sensibly placed duplicate in programming.
 
  


Closed Thread


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command failed: device-mapper: reload ioctl failed: Invalid argument azza Programming 2 01-10-2011 04:16 AM
Please Help me : Sendto: Invalid argument PF_PACKET SOCK_DGRAM htons(ETH_P_IP) tuxtuxtux Linux - Networking 3 03-24-2010 07:08 AM
sendto: Invalid argument netbsd quantt Programming 3 02-14-2009 03:29 AM
message sending failed : Error[22 ] invalid argument .....but each and every argument rakeshranjanjha Linux - Software 2 01-08-2008 12:22 AM
sendto: invalid argument Yury Programming 12 11-04-2006 07:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:54 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