Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
xxx_inet.c
Go to the documentation of this file.00001 #include <stdio.h>
00002 #include <stdlib.h>
00003
00004 char * xxx_name_to_inet( char * host ) ;
00005
00006 #include <X11/Xlib.h>
00007
00008 Display *theDisp;
00009
00010 int main( int argc , char * argv[] )
00011 {
00012 char * cpt ;
00013 char * nam = xxx_name_to_inet(argv[1]) ;
00014 printf("%s\n",nam) ; free(nam) ;
00015
00016 theDisp=XOpenDisplay(NULL) ;
00017 if( theDisp == NULL ) exit(1) ;
00018 nam = DisplayString(theDisp) ; printf("%s\n",nam) ;
00019 cpt = strstr(nam,":") ; *cpt = '\0' ;
00020 nam = xxx_name_to_inet(nam) ;
00021 printf("%s\n",nam) ; free(nam) ;
00022 exit(0) ;
00023 }
00024
00025 #include <sys/types.h>
00026 #include <sys/socket.h>
00027 #include <netinet/in.h>
00028 #include <netdb.h>
00029 #include <stdio.h>
00030 #include <arpa/inet.h>
00031
00032
00033
00034
00035
00036
00037
00038
00039 char * xxx_name_to_inet( char * host )
00040 {
00041 struct hostent * hostp ;
00042 char * iname = NULL , * str ;
00043 int ll ;
00044
00045 if( host == NULL || host[0] == '\0' ) return NULL ;
00046
00047 hostp = gethostbyname(host) ; if( hostp == NULL ) return NULL ;
00048
00049 str = inet_ntoa(*((struct in_addr *)(hostp->h_addr))) ;
00050 if( str == NULL || str[0] == '\0' ) return NULL ;
00051
00052 ll = strlen(str) ; iname = AFMALL(char, ll+1) ; strcpy(iname,str) ;
00053 return iname ;
00054 }