Solved

invalid argument in sendto

Posted on 2009-05-07
4
478 Views
Last Modified: 2012-08-13
anyone care to tell me why? code compiles fine but when trying to run the send to gives me an Invalid Argument in the errno
int sock_fd;
 

AARP_Packet* tempAARP = (AARP_Packet*) malloc(sizeof(AARP_Packet));
 

/*how I initialize the aarp_sockaddr port is defined but not shown here*/

bzero((char *)&aarp_sockaddr,sizeof(aarp_sockaddr));

aarp_sockaddr.sin_family = AF_INET;

bcopy(hp->h_addr_list[0], (char *)&aarp_sockaddr.sin_addr,hp->h_length);

aarp_sockaddr.sin_port = htons(port);
 

flag = sendto(sock_fd, (void*)tempAARP, sizeof(AARP_Packet), 0, (struct sockaddr *)&aarp_sockaddr, sizeof(aarp_sockaddr));

			if (flag == -1){

				perror("Error: Sending AARP Packet failed \n");

				close(sock_fd);

				exit(1);

			}

Open in new window

0
Comment
Question by:kuntilanak
  • 2
  • 2
4 Comments
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24331177
Your sample shows sock_fd is never initialized, or opened, so likely sendto is complaining of a bad descriptor.
0
 

Author Comment

by:kuntilanak
ID: 24331216
I actually did, just forgot to put it above
/* create socket */

	sock_fd = socket(PF_INET,SOCK_DGRAM,0);

	if (sock_fd < 0)

	{

		perror("Error: Socket creation failed\n");

		exit(1);

	}

Open in new window

0
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 500 total points
ID: 24331594
Where is .sin_port initialized and to what value? Your comment is before the bzero() call, so I hope you are setting the port after the bzero?
0
 

Author Comment

by:kuntilanak
ID: 24331679
oh that's the problem.. thanks for pointing that out :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
canBalance challenge 34 70
copyEndy  challenge 15 85
bunnyEars2 challenge 6 107
Adjust the position 3 49
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now