1. ip no ---> Internet name..
Date: Sun, 13 Jun 1993 01:55:36 GMT
: Was wondering if anyone could help me out with this.....
: If I have an ip no... say 128.164.136.204
: and I want to figure out what the name is... how do I do it?
: I know how to do a gethostbyname() to use the NAME to get a number.
: Now how do I get a name from a number?
: I tried playing with gethostbyaddr, but I can NOT get it to work
: right.
: Does anyone have a clue?
: A 5-liner of C-code describing how to do this would be appreciated BIG-TIME.
Well, I can't do it in 5 lines, but this should work :-)
( compiled with gcc, run it by typing name a.b.c.d
where 'name' is what you called the executable
'a.. ' is an IP address )
/*
Program to find a hostname by specifying an IP address
to gethostbyaddr().
Ian Couroulis.
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
main(int argc, char **argv)
{
struct hostent *hp;
int x;
int a,b,c,d;
char caddr[BUFSIZ];
int addr;
for(x=1;x<argc;x++){
sscanf(argv[x],"%d.%d.%d.%d",&a,&b,&c,&d);
addr = d+(c<<8)+(b<<16)+(a<<24);
hp = gethostbyaddr(&addr, sizeof(addr), AF_INET);
if(hp==NULL){
(void) fprintf(stderr,"Address not found\n");
exit(-1);
}
printf("%s\n",hp->h_name);
}
Ian.
--
+------------------------------------------------------------------------+
|Ian Couroulis | . | " Errors, like straws |
|Dept. Comp. & Info Sciences | _--_|\ | upon the surface |
|UC of Northern Victoria | / \ | flow; He who would |
|Victoria, Australia. | \_.--.*/<-here | search for pearls |
+------------------------------------------------------------------------+
2. RH 7 Instalation Troubles - LILO
3. Windows95 box -> Linux Box (Static IP) -> Intranet -> Internet?
4. Laptop Power Management - a Start (Western Digital chips only)
5. win95->linux(gateway)->isdn->internet (ip-masq question?)
6. Oracle Cluster Problem
7. IP Masq: Win95 -> linux -> internet - Problem solved!
8. Access to UNIX User Groups and Publications
9. Internet<-T1->Work(class c)<-pppx->Home (5 IP's)?
10. OS/2 TCIP/IP -> Linux -> Internet
11. Win95 => Linux => Internet via IP-Masq - Any thoughts?
12. ip.h ip->ip_src ip->ip_dst are the same???
13. Samba problem: WinXP <-> ADSL <-> Internet <-> Cable <-> Linux