0

I have two C programs running on separate computers, and I'm having some trouble sending UDP packets from one machine to the other. I've tested the client/server communication pieces of code on the same machine using a localhost, and everything seemed fine, so I don't think the problem is in my code. The server program is running on an Ubuntu laptop, and the client program is running on a Windows XP desktop. Right now, I simply have them both connected through a linksys wrt54gs router.

Every time I try to connect, I get the error "Cannot resolve address "10.0.24.100" " from the client PC when trying to establish a connection. (I can provide some code if anyone thinks that will help.) It's also giving me windows socket error code 11004.

"The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for. The usual example for this is a host name-to-address translation attempt (using gethostbyname or WSAAsyncGetHostByName) which uses the DNS (Domain Name Server). An MX record is returned but no A record—indicating the host itself exists, but is not directly reachable."

I have no idea how to remedy this. However, the host PC is giving me a success message for sending data. (Is this because it's UDP?)

I think the problem is related to my lack of networking experience. This is my first time trying to send UDP data in C, and I'm relatively sure the client can't see the server because I haven't done something right in the settings somewhere. I'm new to linux networking, so I'm not sure how to ensure that the client can see my server in linux.

So far, I've tried two different routers to no avail. The LEDs come on when I plug the Ethernet cables in. I'm really not sure what else I need to do with the router to facilitate this communication. How can I make sure that the two machines can see each other? Do I have to change the IP of the router/computers? How would I go about doing this? I think there's something basic that I'm missing here. Any help would be much appreciated.

UPDATE

Here's the UDP Client Code:

int argc;
char **argv;

#define DEFAULT_PORT 61003
#define DEFAULT_PROTO SOCK_DGRAM

...

int UDPTrack(int argc, char **argv)
{

short pan1, tilt1;
char c = 'l';
char Buffer[128];
//server hardcoded in
char *server_name= "10.0.24.100";
unsigned short port = DEFAULT_PORT;
int retval, loopflag = 0;
int i, loopcount, maxloop=-1;
unsigned int addr;
int socket_type = DEFAULT_PROTO;
struct sockaddr_in server;
struct hostent *hp;
WSADATA wsaData;
SOCKET  conn_socket;
//radar data struct
struct RadarData
{
    unsigned int messageID : 32;
    unsigned int time : 32;
    float az;
    float el;
};
 struct RadarData receivedData;

if (argc >1)
   {
    for(i=1; i<argc; i++)
    {
        if ((argv[i][0] == '-') || (argv[i][0] == '/'))
       {
            switch(tolower(argv[i][1]))
             {
                case 'p':
                    if (!stricmp(argv[i+1], "TCP"))
                        socket_type = SOCK_STREAM;
                    else if (!stricmp(argv[i+1], "UDP"))
                        socket_type = SOCK_DGRAM;
                    else
                        Usage(argv[0]);
                    i++;
                    break;
                case 'n':
                    server_name = argv[++i];
                    break;
                case 'e':
                    port = atoi(argv[++i]);
                    break;
                case 'l':
                    loopflag =1;
                    if (argv[i+1]) {
                        if (argv[i+1][0] != '-')
                            maxloop = atoi(argv[i+1]);
                    }
                    else
                        maxloop = -1;
                    i++;
                    break;
                default:
                    Usage(argv[0]);
                    break;
            }
        }
        else
            Usage(argv[0]);
    }
}

if ((retval = WSAStartup(0x202, &wsaData)) != 0)
{
   fprintf(stderr,"Client: WSAStartup() failed with error %d\n", retval);
    WSACleanup();
    return -1;
}
else
   printf("Client: WSAStartup() is OK.\n");

//ERROR HAPPENS SOMEWHERE IN HERE

 if (port == 0)
{
    Usage(argv[0]);
}
// Attempt to detect if we should call gethostbyname() or gethostbyaddr()
if (isalpha(server_name[0]))
{   // server address is a name
    hp = gethostbyname(server_name);
}
else
{ // Convert nnn.nnn address to a usable one
    addr = inet_addr(server_name);
    hp = gethostbyaddr((char *)&addr, 4, AF_INET);
}
if (hp == NULL )
{
    fprintf(stderr,"Client: Cannot resolve address \"%s\": Error %d\n", server_name, WSAGetLastError());
    WSACleanup();
        system("Pause");

    exit(1);
}
else
   printf("Client: gethostbyaddr() is OK.\n");

I can never get past here.

6
  • UDP streams dont use states or connection, its just streams of data, you will not have a connection between client and server. How are you tring to connect client to server??? You can only do this by implementing client/server on your code. You can test the link betwwen both machines with ping.
    – Diogo
    Jul 14, 2011 at 16:06
  • Sorry, I should have clarified. I was referring to the computer receiving data as the 'client' and the computer sending data as the 'server'.
    – Mike
    Jul 14, 2011 at 16:53
  • 1
    So to test connectivity between both you can just use with ping. If ping works then you can test your aplication. It would be a good strategy of test.
    – Diogo
    Jul 14, 2011 at 16:59
  • You can greatly simplify your testbed network by installing a NIC or USB Ethernet adapter in the client and server PCs, and then assigning static IP addresses. Connect the NICs to each other using a crossover cable or each Ethernet port to a switch. You now have the simplest LAN possible.
    – sawdust
    Jul 14, 2011 at 19:25
  • I am now able to ping the laptop sending data from the desktop (supposed to be) receiving data. I am still getting the same error when trying to use my program.
    – Mike
    Jul 14, 2011 at 21:00

2 Answers 2

1

In the MSDN reference there is an example for a check of the addr result from inet_addr()function. You might just feed an invalid IP address.

The documetation for gethostbyname() suggests that you can call it even if the "name" is an ip address - no need to call inet_addr() at all.

1
  • this makes sense in principle to me... would you mind providing a bit of code? Thanks.
    – Mike
    Jul 15, 2011 at 13:08
0

The message "Cannot resolve address" suggests that you may be supplying an incorrect value to a getHostByName() API function

Note that "localhost" is a valid host-name but "10.0.24.100" is not, though some APIs will do the right thing anyway.

Alternatively your name-resolution (typically DNS) client or server might be mis-configured.

Posting a small (but compilable) sample of your code might help.

For interest:

C:\>perl -MSocket -e "print inet_ntoa(scalar gethostbyname('superuser.com'))"
64.34.119.12

C:\>perl -MSocket -e "print inet_ntoa(scalar gethostbyname('localhost'))"
127.0.0.1

C:\>perl -MSocket -e "print inet_ntoa(scalar gethostbyname('127.0.0.1'))"
127.0.0.1

C:\>perl -MSocket -e "print inet_ntoa(scalar gethostbyname('10.1.2.3'))"
10.1.2.3
C:\>
1
  • I provided the code above. Hopefully that will clarify my problem.
    – Mike
    Jul 14, 2011 at 21:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .