Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

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    Return the Internet address (in 'dot' format, as a string)
00034    given the name of the host.  If NULL is returned, some
00035    error occurrrrred.  The return string is malloc-ed and should
00036    be free-d someday.
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 }
 

Powered by Plone

This site conforms to the following standards: