C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 03-16-2006, 01:41 PM   #1
Registered User
 
Join Date: Oct 2001
Posts: 224
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

Last edited by c++.prog.newbie; 03-16-2006 at 03:59 PM.
c++.prog.newbie is offline   Reply With Quote
Old 03-16-2006, 04:46 PM   #2
Registered User
 
Join Date: Oct 2001
Posts: 224
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 ?
c++.prog.newbie is offline   Reply With Quote
Old 03-20-2006, 02:16 AM   #3
Registered User
 
Join Date: Oct 2001
Posts: 224
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

Last edited by c++.prog.newbie; 03-20-2006 at 02:19 AM.
c++.prog.newbie is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
sendto: Invalid argument netbsd quantt C Programming 5 02-15-2009 08:55 PM
Error in sending/receiving strings while using sendto() and recvfrom() ferenczi Networking/Device Communication 3 11-28-2008 12:12 AM
Raw socket and sendto() matB Networking/Device Communication 4 07-10-2008 05:07 PM
sendto Socket packet size bj00 Networking/Device Communication 0 07-27-2007 11:05 AM
Socket Datagram info sendto(), recvfrom() siluro C Programming 1 02-20-2005 12:10 PM


All times are GMT -6. The time now is 09:24 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22