LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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
 
LinkBack Search this Thread
Old 09-10-2010, 07: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 07:08 PM.
 
Old 09-11-2010, 02:01 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
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
Trackbacks are Off
Pingbacks are On
Refbacks are 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 03:16 AM
Please Help me : Sendto: Invalid argument PF_PACKET SOCK_DGRAM htons(ETH_P_IP) tuxtuxtux Linux - Networking 3 03-24-2010 06:08 AM
sendto: Invalid argument netbsd quantt Programming 3 02-14-2009 02:29 AM
message sending failed : Error[22 ] invalid argument .....but each and every argument rakeshranjanjha Linux - Software 2 01-07-2008 11:22 PM
sendto: invalid argument Yury Programming 12 11-04-2006 06:06 AM


All times are GMT -5. The time now is 08:31 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 Google+: linuxquestions
Open Source Consulting | Domain Registration