The world's most popular open source database
#include <my_global.h>#include <m_ctype.h>#include <my_sys.h>#include <m_string.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netdb.h>#include <my_net.h>#include <my_getopt.h>Include dependency graph for resolveip.c:

Go to the source code of this file.
Defines | |
| #define | RESOLVE_VERSION "2.3" |
Functions | |
| static void | print_version (void) |
| static void | usage (void) |
| static my_bool | get_one_option (int optid, const struct my_option *opt __attribute__((unused)), char *argument __attribute__((unused))) |
| static int | get_options (int *argc, char ***argv) |
| int | main (int argc, char **argv) |
Variables | |
| int | h_errno |
| static my_bool | silent |
| static struct my_option | my_long_options [] |
| #define RESOLVE_VERSION "2.3" |
| static my_bool get_one_option | ( | int | optid, | |
| const struct my_option *opt | __attribute__((unused)), | |||
| char *argument | __attribute__((unused)) | |||
| ) | [static] |
Definition at line 74 of file resolveip.c.
References exit, print_version(), and usage().
00076 { 00077 switch (optid) { 00078 case 'V': print_version(); exit(0); 00079 case 'I': 00080 case '?': 00081 usage(); 00082 exit(0); 00083 } 00084 return 0; 00085 }
Here is the call graph for this function:

| static int get_options | ( | int * | argc, | |
| char *** | argv | |||
| ) | [static] |
Definition at line 89 of file resolveip.c.
References exit, get_one_option(), handle_options(), my_long_options, and usage().
00090 { 00091 int ho_error; 00092 00093 if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option))) 00094 exit(ho_error); 00095 00096 if (*argc == 0) 00097 { 00098 usage(); 00099 return 1; 00100 } 00101 return 0; 00102 } /* get_options */
Here is the call graph for this function:

| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Definition at line 106 of file resolveip.c.
References err, error, exit, get_options(), h_errno, in_addr_t, memcpy, my_charset_latin1, MY_INIT, my_isdigit, my_progname, p, and silent.
00107 { 00108 struct hostent *hpaddr; 00109 in_addr_t taddr; 00110 char *ip,**q; 00111 int error=0; 00112 00113 MY_INIT(argv[0]); 00114 00115 if (get_options(&argc,&argv)) 00116 exit(1); 00117 00118 while (argc--) 00119 { 00120 ip = *argv++; 00121 00122 if (my_isdigit(&my_charset_latin1,ip[0])) 00123 { 00124 taddr = inet_addr(ip); 00125 if (taddr == htonl(INADDR_BROADCAST)) 00126 { 00127 puts("Broadcast"); 00128 continue; 00129 } 00130 if (taddr == htonl(INADDR_ANY)) 00131 { 00132 if (!taddr) 00133 puts("Null-IP-Addr"); 00134 else 00135 puts("Old-Bcast"); 00136 continue; 00137 } 00138 00139 hpaddr = gethostbyaddr((char*) &(taddr), sizeof(struct in_addr),AF_INET); 00140 if (hpaddr) 00141 { 00142 if (silent) 00143 puts(hpaddr->h_name); 00144 else 00145 { 00146 printf ("Host name of %s is %s", ip,hpaddr->h_name); 00147 #ifndef __NETWARE__ 00148 /* this information is not available on NetWare */ 00149 for (q = hpaddr->h_aliases; *q != 0; q++) 00150 (void) printf(", %s", *q); 00151 #endif /* __NETWARE__ */ 00152 puts(""); 00153 } 00154 } 00155 else 00156 { 00157 error=2; 00158 fprintf(stderr,"%s: Unable to find hostname for '%s'\n",my_progname, 00159 ip); 00160 } 00161 } 00162 else 00163 { 00164 hpaddr = gethostbyname(ip); 00165 if (!hpaddr) 00166 { 00167 const char *err; 00168 fprintf(stderr,"%s: Unable to find hostid for '%s'",my_progname,ip); 00169 switch (h_errno) { 00170 case HOST_NOT_FOUND: err="host not found"; break; 00171 case TRY_AGAIN: err="try again"; break; 00172 case NO_RECOVERY: err="no recovery"; break; 00173 case NO_DATA: err="no_data"; break; 00174 default: err=0; 00175 } 00176 if (err) 00177 fprintf(stderr,": %s\n",err); 00178 else 00179 fprintf(stderr,"\n"); 00180 error=2; 00181 } 00182 else if (silent) 00183 { 00184 struct in_addr in; 00185 memcpy((char*) &in.s_addr, (char*) *hpaddr->h_addr_list, 00186 sizeof (in.s_addr)); 00187 puts(inet_ntoa(in)); 00188 } 00189 else 00190 { 00191 char **p; 00192 for (p = hpaddr->h_addr_list; *p != 0; p++) 00193 { 00194 struct in_addr in; 00195 memcpy(&in.s_addr, *p, sizeof (in.s_addr)); 00196 printf ("IP address of %s is %s\n",ip,inet_ntoa(in)); 00197 } 00198 } 00199 } 00200 } 00201 exit(error); 00202 }
Here is the call graph for this function:

| static void print_version | ( | void | ) | [static] |
Definition at line 55 of file resolveip.c.
References MACHINE_TYPE, my_progname, RESOLVE_VERSION, and SYSTEM_TYPE.
00056 { 00057 printf("%s Ver %s, for %s (%s)\n",my_progname,RESOLVE_VERSION, 00058 SYSTEM_TYPE,MACHINE_TYPE); 00059 }
| static void usage | ( | void | ) | [static] |
Definition at line 62 of file resolveip.c.
References my_long_options, my_print_help(), my_print_variables(), my_progname, and print_version().
00063 { 00064 print_version(); 00065 puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n"); 00066 puts("Get hostname based on IP-address or IP-address based on hostname.\n"); 00067 printf("Usage: %s [OPTIONS] hostname or IP-address\n",my_progname); 00068 my_print_help(my_long_options); 00069 my_print_variables(my_long_options); 00070 }
Here is the call graph for this function:

| int h_errno |
Referenced by main(), and my_gethostbyname_r().
struct my_option my_long_options[] [static] |
Initial value:
{
{"help", '?', "Displays this help and exits.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"info", 'I', "Synonym for --help.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"silent", 's', "Be more silent.", (gptr*) &silent, (gptr*) &silent,
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"version", 'V', "Displays version information and exits.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
}
Definition at line 41 of file resolveip.c.
Definition at line 39 of file resolveip.c.
1.4.7

