Professional Web Applications Themes

gethostbyaddr returning null for CNAME records - UNIX Programming

Hello: I am using gcc on RedHat Linux 9. When I try to do a reverse dns query using gethostbyaddr, it works fine for hosts that have a PTR record, but it returns null for hosts that have a CNAME record. Any ideas how to work around this? Here is an example: dig -x 66.54.79.4 Gives me this answer: 4.79.54.66.in-addr.arpa. 35499 IN PTR mail.JAMMConsulting.com. And: dig -x 64.61.26.100 Gives me this answer: 100.26.61.64.in-addr.arpa. 40544 IN CNAME 100.jfax.com. I wrote this test program: #include <netdb.h> #include <netinet/in.h> #include <sys/socket.h> int main(argc, argv) int argc; char *argv[]; { /* Perform the lookup ...

  1. #1

    Default gethostbyaddr returning null for CNAME records

    Hello:

    I am using gcc on RedHat Linux 9.

    When I try to do a reverse dns query using gethostbyaddr, it works
    fine for hosts that have a PTR record, but it returns null for hosts
    that have a CNAME record. Any ideas how to work around this?

    Here is an example:
    dig -x 66.54.79.4
    Gives me this answer:
    4.79.54.66.in-addr.arpa. 35499 IN PTR mail.JAMMConsulting.com.

    And:
    dig -x 64.61.26.100
    Gives me this answer:
    100.26.61.64.in-addr.arpa. 40544 IN CNAME 100.jfax.com.

    I wrote this test program:
    #include <netdb.h>
    #include <netinet/in.h>
    #include <sys/socket.h>

    int main(argc, argv)
    int argc;
    char *argv[];
    {
    /* Perform the lookup */
    /*unsigned long network_ip = htonl(0x42364f04); /* IP 66.54.79.4 */
    unsigned long network_ip = htonl(0x403d1a64); /* IP 64.61.26.100 */

    struct hostent *result;
    result = gethostbyaddr((const void*)&network_ip, sizeof(unsigned long), AF_INET);
    if( result == NULL ) {
    printf( "Hostentry is null\n" );
    } else {
    if( result->h_name == NULL ) {
    printf( "Hostname is null\n" );
    } else
    printf( "Got back %s\n", result->h_name );
    }
    }

    when I run it with the network ip for 66.54.79.4, I get back
    mail.JAMMConsulting.com which is what I expected, but when I run it
    with the network ip for 64.61.26.100, I get back a null result
    pointer.

    Any ideas how to work around this?

    Thanks
    Neil

    --
    Neil Aggarwal, JAMM Consulting, (972)612-6056, www.JAMMConsulting.com
    FREE! Valuable info on how your business can reduce operating costs by
    17% or more in 6 months or less! => http://newsletter.JAMMConsulting.com
    Neil Guest

  2. #2

    Default Re: gethostbyaddr returning null for CNAME records

    In article <google.com>,
    com (Neil Aggarwal) wrote: 

    The CNAME record has to point to a name that has a PTR record.
     

    100.jfax.com has no PTR record. What name do you expect the reverse
    lookup to return?

    Go read RFC 2317 again....

    --
    Barry Margolin, mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    Barry Guest

  3. #3

    Default Re: gethostbyaddr returning null for CNAME records

    Barry:

    Let me try to understand what is happening here:

    dig -x 64.61.26.100
    gives me a CNAME record of 100.jfax.com.

    So, I look up 100.jfax.com with this query:

    dig 100.jfax.com any

    I get no answers. Is that why the gethostbyaddr is failing?

    I expected it to return 100.jfax.com

    Thanks,
    Neil

    --
    Neil Aggarwal, JAMM Consulting, (972)612-6056, www.JAMMConsulting.com
    FREE! Valuable info on how your business can reduce operating costs by
    17% or more in 6 months or less! => http://newsletter.JAMMConsulting.com


    Barry Margolin <mit.edu> wrote in message news:<ash.giganews.com>... 
    >
    > The CNAME record has to point to a name that has a PTR record.

    >
    > 100.jfax.com has no PTR record. What name do you expect the reverse
    > lookup to return?
    >
    > Go read RFC 2317 again....[/ref]
    Neil Guest

  4. #4

    Default Re: gethostbyaddr returning null for CNAME records

    In article <google.com>,
    com (Neil Aggarwal) wrote:
     

    Yes.
     

    Why would you expect that, if there's no such record?

    A CNAME record is an alias. It means "the name you asked for doesn't
    have any records of its own, look up the records attached to the
    following records instead".

    As an ogy, a CNAME record is like a Unix symbolic link. If the link
    points to a nonexistent filename, trying to open the link fails -- it
    doesn't treat the name that it points to as the "contents" of the file.

    --
    Barry Margolin, mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    Barry Guest

  5. #5

    Default Re: gethostbyaddr returning null for CNAME records


    "Neil Aggarwal" <com> wrote in message
    news:google.com...

     


    Your expectation is wrong. The function is get*HOST*byaddr, not
    get*WhateverHappensToBeThere*byaddr. Since there is no host record, it
    correctly returns NULL.

    The gethostbyaddr function tries to resolve an IP address to a PTR
    record to obtain the host name. In this case, there is no host name. If you
    look in the 'hostent' structure that gethostbyaddr returns, there is no
    place to put 'the canonical name for the IP address'.

    Basically, a CNAME for an IP address is not a host name.

    DS



    David Guest

  6. #6

    Default Re: gethostbyaddr returning null for CNAME records

    On Thu, 26 Feb 2004 15:19:33 -0800,
    David Schwartz <com> wrote:

     


    It may be if it is part of a rfc2317 style in-addr.arpa delegation. The
    name to which the CNAME refers to must then resolve to a PTR RR for the
    real hostname and the latter seems to be missing.


    Villy
    Villy Guest

Similar Threads

  1. Returning Records from <cfquery>
    By pnugent in forum Macromedia ColdFusion
    Replies: 3
    Last Post: June 24th, 04:26 AM
  2. Periodically returning no records
    By melancthon in forum Coldfusion Database Access
    Replies: 3
    Last Post: March 2nd, 09:39 PM
  3. Is Null returning incosistent results -- help!
    By Jason in forum Microsoft SQL / MS SQL Server
    Replies: 3
    Last Post: August 12th, 05:55 PM
  4. OnEditCommand - .FindControl Returning Null
    By George Durzi in forum ASP.NET General
    Replies: 0
    Last Post: July 14th, 09:54 PM
  5. OnEditCommand - FindControl returning Null
    By George Durzi in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: July 14th, 09:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139