Results 1 to 2 of 2
Here's a simple program that uses gethostbyname
Code:
#include<stdio.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<error.h>
#include<strings.h>
#include<unistd.h>
#include<arpa/inet.h>
#include<netdb.h> //struct hostent
int main()
{
char s[INET_ADDRSTRLEN]; //Buffer to store the ip
...
- 03-26-2010 #1Just Joined!
- Join Date
- Mar 2010
- Posts
- 10
Help with gethostbyname
Here's a simple program that uses gethostbyname

I just want to know why the result differ when I give nameofanysite.com as input and "xxx.nameofsite.com" as input . Also every time I run it even though giving the same site as input i get a list of different IP address list.Why is so.Code:#include<stdio.h> #include<stdlib.h> #include<sys/socket.h> #include<sys/types.h> #include<netinet/in.h> #include<error.h> #include<strings.h> #include<unistd.h> #include<arpa/inet.h> #include<netdb.h> //struct hostent int main() { char s[INET_ADDRSTRLEN]; //Buffer to store the ip char **ptr; char str[100]; //Name of host on which lookup has to be performed struct hostent *hptr; printf("Enter the string :");//Enter the name of host gets(str); printf("\n"); if((hptr=gethostbyname(str))==NULL) //Get host information { printf("Error in host name :"); //Error message exit(1); } printf("host officail name %s",hptr->h_name); //Print host officail name printf("\n\n\n"); for(ptr=hptr->h_aliases;*ptr!=NULL;ptr++) { printf("Aliases : %s\n",*ptr); //Print Alias name of the host } printf("\n"); for(ptr=hptr->h_addr_list;*ptr!=NULL;ptr++) //Print all ip address use by host { printf("Adress list %s\n",inet_ntop(AF_INET,ptr,s,sizeof(s))); } }
thanx
Note .Please READ XXX AS www
- 03-27-2010 #2
Well, as a general concept, site dot com is a top level domain,
while www dot site dot com literally means host www
at site dot com. So www is not part of the http:
protocol prefix, but is a hostname, traditionally used for web servers.
site dot com is just the domain, with no host specified.


Reply With Quote