Thread: error using sendto

  1. #1
    Registered User
    Join Date
    Oct 2001

    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 and the actual IP address but both give the same error

    here is the code were i set the addr and use sendto

            tempaddr.sin_family = AF_INET;
            tempaddr.sin_port = htons(0);
            tempaddr.sin_addr.s_addr = inet_addr("");
            memset(&(tempaddr.sin_zero), '\0', 8);
            if((sent = sendto(localsock, argv[2], MAXMSGSIZE-1, 0, (struct sockaddr *)&tempaddr, sin_size)) == -1)
                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.

  2. #2
    Registered User
    Join Date
    Oct 2001
    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 ?

  3. #3
    Registered User
    Join Date
    Oct 2001
    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
    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
    [adam@d198-53-226-104 ~]$ ./cs help
    h_addr_list[0] is: \uffff5
    h_name is:
    h_addrtype is: 2
    h_length is: 4
    addr is:
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

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