gethostbyaddr does not work 
Author Message
 gethostbyaddr does not work

dear subscriber

i wrote a program that implements the gethostbyaddr
feature, but it does not work.

i get the error code 11004:
        /* Valid name, no data record of requested type */
        #define WSANO_DATA              (WSABASEERR+1004)

the function gethostbyname is working fine.

where is the problem ?

int main(int argc, char *argv[])
{
        long ip; HOSTENT *host;

        ret = WSAStartup(MAKEWORD(1,1), &wsaData);
        if (argc != 2)
        {
                fprintf(stderr, "\n USAGE: GetHostByAddress ipaddress\n\n");
                return(0);
        }
        ip = TransformIPStringToLongValue(argv[1]);
        ip = htonl(ip); // network order
        while (WSAIsBlocking());
        host = gethostbyaddr((char *)&ip, 4, AF_INET);
        if (host == NULL) fprintf(stderr, "\n The gethostbyaddr error code is %d", WSAGetLastError());
        else fprintf(stdout, "\n The hostname of adress %s is %s\n\n", argv[1], host->h_name);
        while (WSAIsBlocking());
        ret = WSACleanup();
        return(0);

Quote:
}

+------------------------------------------------------------------------------------------+
| Erwin Brandenberger     http://www.*-*-*.com/ |

| Human Engineering AG                                                                     |
| Schoenenbergerweg 9a, 8405 Winterthur-Seen , SWITZERLAND                                 |
| CALL: ++41 (0)52-238 07 39  FAX: ++41 (0)52-232 06 20                                    |
+------------------------------------------------------------------------------------------+


Fri, 25 Aug 2000 03:00:00 GMT  
 gethostbyaddr does not work

Quote:

>i get the error code 11004:
>    /* Valid name, no data record of requested type */
>    #define WSANO_DATA              (WSABASEERR+1004)

Most of us don't know what "WSA" might be, and don't want to know.

Quote:
>where is the problem ?

In you code?

Quote:
>    long ip; HOSTENT *host;

What's HOSTENT?

Quote:
>    ret = WSAStartup(MAKEWORD(1,1), &wsaData);
>    if (argc != 2)
>    {
>            fprintf(stderr, "\n USAGE: GetHostByAddress ipaddress\n\n");
>            return(0);
>    }
>    ip = TransformIPStringToLongValue(argv[1]);
>    ip = htonl(ip); // network order

Are you sure that "ip" contains what you think it contains?

Quote:
>    while (WSAIsBlocking());

This is pretty strange stuff. Try with standard functions first,  and
if this works, then you may consider using your black magic - I don't
appreciate it.

Quote:
>    host = gethostbyaddr((char *)&ip, 4, AF_INET);
>    if (host == NULL) fprintf(stderr, "\n The gethostbyaddr error code is %d", WSAGetLastError());
>    else fprintf(stdout, "\n The hostname of adress %s is %s\n\n", argv[1], host->h_name);
>    while (WSAIsBlocking());
>    ret = WSACleanup();

Try something like this:

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
int main(int argc, char **argv)
{
        struct hostent *hp;
        long ip;
        ip = atol(*++argv);
        printf ("ip: 0x%x\n", ip);
        if ((hp = gethostbyaddr((char *)&ip, sizeof(ip), AF_INET)) == NULL) {
                perror ("gethostbyaddr"); exit (1);
        }
        printf ("hp: %s\n", hp ? hp->h_name : "unknown host");

Quote:
}

Wolfgang Denk



If you had better tools,  you could more effectively demonstrate your
total incompetence.



Fri, 25 Aug 2000 03:00:00 GMT  
 gethostbyaddr does not work

Quote:

> dear subscriber

> i wrote a program that implements the gethostbyaddr
> feature, but it does not work.

> i get the error code 11004:
>         /* Valid name, no data record of requested type */
>         #define WSANO_DATA              (WSABASEERR+1004)

> the function gethostbyname is working fine.

> where is the problem ?

> int main(int argc, char *argv[])
> {
>         long ip; HOSTENT *host;

>         ret = WSAStartup(MAKEWORD(1,1), &wsaData);
>         if (argc != 2)
>         {
>                 fprintf(stderr, "\n USAGE: GetHostByAddress ipaddress\n\n");
>                 return(0);
>         }
>         ip = TransformIPStringToLongValue(argv[1]);
>         ip = htonl(ip); // network order
>         while (WSAIsBlocking());
>         host = gethostbyaddr((char *)&ip, 4, AF_INET);
>         if (host == NULL) fprintf(stderr, "\n The gethostbyaddr error code is %d", WSAGetLastError());
>         else fprintf(stdout, "\n The hostname of adress %s is %s\n\n", argv[1], host->h_name);
>         while (WSAIsBlocking());
>         ret = WSACleanup();
>         return(0);
> }

> +------------------------------------------------------------------------------------------+

  Hi, Erwin.
Since your problem is platform-specific (WinSocks, it seems?),
your best bet would be to ask your platform gurus in a platform-
specific newsgroup, such as
        comp.os.ms-windows.programmer
        comp.os.ms-windows.misc

        Regards,
                Alex Krol



Fri, 25 Aug 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. C++/ATL/ADO - Intellisense not working (statement completion options) not working

2. Where is the rough work done?

3. Done it - Quick C now works

4. this code works on SGI does not work on linux

5. CMap Lookup not working (at least I cannot get it to work)

6. Program not work at release mode but work at debug mode

7. GetPrivateProfileSectionNames not working in 98 or ME but does work in 2000

8. Window NT BitMap Works Windows95 BitMap Does not Work

9. static member inheritance not doing what I want...

10. Class not registered when doing COM interop

11. Not operator NOT working (!)

12. Strings doing what they are not supposed to...???

 

 
Powered by phpBB® Forum Software