-
error using sendto
when i use sento (UDP) in my program trying to send a mesg from one computer to the same one i get this error
sendto: Can't assign requested address
i tried 127.0.0.1 and the actual IP address but both give the same error
here is the code were i set the addr and use sendto
Code:
tempaddr.sin_family = AF_INET;
tempaddr.sin_port = htons(0);
tempaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
memset(&(tempaddr.sin_zero), '\0', 8);
if((sent = sendto(localsock, argv[2], MAXMSGSIZE-1, 0, (struct sockaddr *)&tempaddr, sin_size)) == -1)
{
perror("sendto");
return -1;
}
anyone know how to solve this problem? or what im doing wrong
-
actually i got a different problem,
how do i get the address from a hostent* (h->h_addr) into a myaddr.sin_addr.s_addr ?
-
:D ok i got that problem figured out, im still getting the error
sendto: Invalid argument
which is printed out using perror("sendto")...
i tried entering the following code for debugging purposes
Code:
cout<<"h_addr_list[0] is: "<<h->h_addr_list[0]<<endl; // same as h_addr
cout<<"h_name is: "<<h->h_name<<endl;
cout<<"h_aliases[0] is: "<<h->h_aliases[0]<<endl;
cout<<"h_addrtype is: "<<h->h_addrtype<<endl;
cout<<"h_length is: "<<h->h_length<<endl;
and if i leave the line with h_aliases uncommented it seems that the program will skip everything until it gets to sendto... which it then prints out the error that i stated above...
if i comment out the aliases line i get the following output
Code:
[adam@d198-53-226-104 ~]$ ./cs d198-53-226-104.abhsia.telus.net help
h_addr_list[0] is: \uffff5
h_name is: d198-53-226-104.abhsia.telus.net
h_addrtype is: 2
h_length is: 4
addr is: 198.53.226.104
sendto: Invalid argument
any idea how to solve this?? i would appreciate any help :D