Address family not supported by protocol

This is a discussion on Address family not supported by protocol within the Networking/Device Communication forums, part of the General Programming Boards category; When I tried to do a send to, I got the following error: Address family not supported by protocol below ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    Address family not supported by protocol

    When I tried to do a send to, I got the following error:

    Address family not supported by protocol

    below is part of my code:

    Code:
     rlen = recvfrom(recv_s,f,sizeof(Frame),0,(struct sockaddr*)&client,&client_len);
    	if (rlen < 0) {
    	    perror("Error: recv failed");
    	    exit(1);
    	}
    
    
    
    if (sendto(recv_s,ack_f,sizeof(Frame),0,(struct sockaddr *)&client,sizeof(client)) != rlen) {
    		perror("Error: Sending message failed");
    		close(recv_s);
    		close(send_s);
    		exit(1);
    	}
    basically the client information is filled from the recvfrom... but I don't know why when it tries to send it back it gives that error

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,249
    Are you properly initializing the sin_family member of the sockaddr_in?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    hmm.. here's what I've done so far.. I tried to print what the sin_family of client after the call to recvfrom and it gives me some huge number... I think it's supposed to be 2 right for AF_INET? So why is it not getting 2 there... weird

  4. #4
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Is sin_family required to be in network-byte-order?
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  5. #5
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,249
    Quote Originally Posted by -EquinoX- View Post
    hmm.. here's what I've done so far.. I tried to print what the sin_family of client after the call to recvfrom and it gives me some huge number... I think it's supposed to be 2 right for AF_INET? So why is it not getting 2 there... weird
    Have you examined its value immediately after the call to recvfrom()? If it's wrong there, then you know you can't rely on the system to correctly set this value for you -- you'll need to do it yourself.

    As far as endianness, I don't seem to remember ever accounting for that while setting this value. The address family is something local to the host. It never goes over the network, so my assumption is that it should be in host byte order. (Besides, you have the macro AF_INET -- it would be kind of silly to have to htons() that value when it's already defined for convenience)
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    I've indirectly specified the AF_INET family and it doesn't complain again now, though now I don't think that it's sending to the correct place... although I've specified the port number as well

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What does this do (Windows API)?
    By EVOEx in forum Windows Programming
    Replies: 4
    Last Post: 12-19-2008, 09:48 AM
  2. I thought pointers were pointers...
    By keira in forum C Programming
    Replies: 19
    Last Post: 08-15-2007, 11:48 PM
  3. DX - CreateDevice - D3DERR_INVALIDCALL
    By Tonto in forum Game Programming
    Replies: 3
    Last Post: 12-01-2006, 06:17 PM
  4. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM
  5. Im so lost at . .
    By hermit in forum C Programming
    Replies: 18
    Last Post: 05-15-2002, 01:26 AM

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