Link to home
Start Free TrialLog in
Avatar of kuntilanak
kuntilanakFlag for United States of America

asked on

invalid argument in sendto

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

Avatar of mrjoltcola
mrjoltcola
Flag of United States of America image

Your sample shows sock_fd is never initialized, or opened, so likely sendto is complaining of a bad descriptor.
Avatar of kuntilanak

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of mrjoltcola
mrjoltcola
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oh that's the problem.. thanks for pointing that out :)