Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6152905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:00:02+00:00 2026-05-23T20:00:02+00:00

/* As usual, make the appropriate includes and declare the variables. */ #include <netinet/in.h>

  • 0
/*  As usual, make the appropriate includes and declare the variables.  */

#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    char *host, **names, **addrs;
    struct hostent *hostinfo;

/*  Set the host in question to the argument supplied with the getname call,
    or default to the user's machine.  */

    if(argc == 1) {
        char myname[256];
        gethostname(myname, 255);
        host = myname;
    }
    else
        host = argv[1];

/*  Make the call to gethostbyname and report an error if no information is found.  */

    hostinfo = gethostbyname(host);
    if(!hostinfo) {
        fprintf(stderr, "cannot get info for host: %s\n", host);
        exit(1);
    }

/*  Display the hostname and any aliases it may have.  */

    printf("results for host %s:\n", host);
    printf("Name: %s\n", hostinfo -> h_name);
    printf("Aliases:");
    names = hostinfo -> h_aliases;
    while(*names) {
        printf(" %s", *names);
        names++;
    }
    printf("\n");

/*  Warn and exit if the host in question isn't an IP host.  */

    if(hostinfo -> h_addrtype != AF_INET) {
        fprintf(stderr, "not an IP host!\n");
        exit(1);
    }

/*  Otherwise, display the IP address(es).  */

    addrs = hostinfo -> h_addr_list;
    while(*addrs) {
        char *ip_str = inet_ntoa(*(struct in_addr *)*addrs); 

        printf(" %s", ip_str);

    /* <BEGIN> Get the host name by IP address */
    struct in_addr addr = {0};
    if (!inet_aton(ip_str, &addr)) {
        printf("Cannot parse IP %s\n", ip_str);
        exit(1);
    }

      struct hostent *remoteHost = gethostbyaddr((void*)&addr, sizeof(addr), AF_INET);
    if (remoteHost == NULL) {
      printf("\nInvalid remoteHost\n");
      exit(1);
    }

    printf("\nOfficial name: %s\n", remoteHost->h_name);
    char **pAlias;
    for(pAlias=remoteHost->h_aliases; *pAlias != 0; pAlias++) {
      printf("\tAlternate name: %s\n", *pAlias);
    }

        /* <End> */
        addrs++;
    }
    printf("\n");
    exit(0);
}

/* Test Run for http://www.yahoo */

user@ubuntu:~/Documents/C$ ./getname2way www.yahoo.com
results for host www.yahoo.com:
Name: any-fp.wa1.b.yahoo.com
Aliases: www.yahoo.com fp.wg1.b.yahoo.com
 209.191.122.70
Official name: ir1.fp.vip.mud.yahoo.com

/* Test Run for http://www.google.com */

user@ubuntu:~/Documents/C$ ./getname2way www.google.com
results for host www.google.com:
Name: www.l.google.com
Aliases: www.google.com
 74.125.225.83
Invalid remoteHost

Why the code doesn’t work for http://www.google.com?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:00:03+00:00Added an answer on May 23, 2026 at 8:00 pm

    The IP address 74.125.225.83 does not have a reverse PTR record. You can always test on the command line with nslookup or dig.

    can’t find 74.125.225.83: Non-existent domain

    http://en.wikipedia.org/wiki/Reverse_DNS_lookup

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So GET forms make the usual urls like .../search/?q=apple Can you make a form
I want to make preview button as usual form button next to submit button(as
We have the usual web.xml for our web application which includes some jsp and
In the usual Strategy Pattern, we make each strategy as a class. Can't we
I am trying to make a query as usual but this time I need
As usual you write in Joomla Development defined('_JEXEC') or die('Restricted access'); I make a
The usual: document.body.addEventListener('touchmove',function(event){event.preventDefault();},false); isn't working for me. I am trying to make my iPad
Caching is the usual strategy that VMs use to make dynamic method dispatch rival
The usual method of URL-encoding a unicode character is to split it into 2
As usual, some background information first: Database A (Access database) - Holds a table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.