1 #include <stdio.h>
2 #include <stdlib.h>
3 
4 char * xxx_name_to_inet( char * host ) ;
5 
6 #include <X11/Xlib.h>
7 
8 Display         *theDisp;
9 
main(int argc,char * argv[])10 int main( int argc , char * argv[] )
11 {
12    char * cpt ;
13    char * nam = xxx_name_to_inet(argv[1]) ;
14    printf("%s\n",nam) ; free(nam) ;
15 
16    theDisp=XOpenDisplay(NULL) ;
17    if( theDisp == NULL ) exit(1) ;
18    nam = DisplayString(theDisp) ; printf("%s\n",nam) ;
19    cpt = strstr(nam,":") ; *cpt = '\0' ;
20    nam = xxx_name_to_inet(nam) ;
21    printf("%s\n",nam) ; free(nam) ;
22    exit(0) ;
23 }
24 
25 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include <netinet/in.h>
28 #include <netdb.h>
29 #include <stdio.h>
30 #include <arpa/inet.h>
31 
32 /*----------------------------------------------------------------
33    Return the Internet address (in 'dot' format, as a string)
34    given the name of the host.  If NULL is returned, some
35    error occurrrrred.  The return string is malloc-ed and should
36    be free-d someday.
37 ------------------------------------------------------------------*/
38 
xxx_name_to_inet(char * host)39 char * xxx_name_to_inet( char * host )
40 {
41    struct hostent * hostp ;
42    char * iname = NULL , * str ;
43    int ll ;
44 
45    if( host == NULL || host[0] == '\0' ) return NULL ;
46 
47    hostp = gethostbyname(host) ; if( hostp == NULL ) return NULL ;
48 
49    str = inet_ntoa(*((struct in_addr *)(hostp->h_addr))) ;
50    if( str == NULL || str[0] == '\0' ) return NULL ;
51 
52    ll = strlen(str) ; iname = AFMALL(char, ll+1) ; strcpy(iname,str) ;
53    return iname ;
54 }
55