Thread: error using sendto

  1. #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.

  2. #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 ?

  3. #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.

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, 05:07 PM
  4. sendto Socket packet size
    By bj00 in forum Networking/Device Communication
    Replies: 0
    Last Post: 07-27-2007, 11:05 AM
  5. Socket Datagram info sendto(), recvfrom()
    By siluro in forum C Programming
    Replies: 1
    Last Post: 02-20-2005, 12:10 PM