#pragma module WHOIS "V1.6" char *whois_version = "V1.6 by JFM" ; /** ** ** WHOIS Utility ** Copyright 2004, Jean-François Mezei, Vaxination Informatique ** Contact: jfmezei@vaxination.ca ** ** To compile: CC/UNSIGNED WHOIS ** ** Permission is granted to use and distribute this utility. ** ** Modification history: ** 27-SEP-2002 V1.5 Productized version ** 28-MAY-2004 V1.6 AS number support, different parsing + update ** ** **/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include "servers.h" #include "asnumbers.h" /****** parameters ****************/ static $DESCRIPTOR(CLI_HOST_NAME, "HOST_NAME"); static $DESCRIPTOR(CLI_SERVER,"SERVER"); static $DESCRIPTOR(CLI_HOST,"HOST"); static $DESCRIPTOR(CLI_OUTPUT,"OUTPUT"); static $DESCRIPTOR(CLI_LIST,"LIST"); static $DESCRIPTOR(CLI_FULL,"FULL"); static $DESCRIPTOR(CLI_BRIEF,"BRIEF"); static $DESCRIPTOR(CLI_PORT,"PORT"); static int cli_host_name_present; static int cli_server_present ; static int cli_host_present ; static int cli_output_present ; static int cli_list_present ; static int cli_full_present ; static int cli_brief_present ; static int cli_port_present ; static unsigned short cli_host_name_len; static unsigned short cli_server_len; static unsigned short cli_host_len; static unsigned short cli_output_len; static char cli_host_name_str[256]; static char cli_server_str[256]; static char cli_output_str[256]; static int cli_port_int ; static $DESCRIPTOR(CLI_HOST_NAME_DESC,cli_host_name_str); static $DESCRIPTOR(CLI_SERVER_DESC,cli_server_str); static $DESCRIPTOR(CLI_OUTPUT_DESC,cli_output_str); struct buffer_struct { long used ; long alloc ; long remain ; char *data ; char *ptr ; /* working pointer */ } ; #define BUFFER_ALLOC_INIT 2000 /****************** TCPIP stuff *************************************/ struct tcpip_iosb_struct { unsigned short status ; unsigned short count ; void *pointer ; } ; /* taken from in.h - for easy reference only * *struct sockaddr_in { * unsigned short sin_family; * unsigned short sin_port; * struct in_addr sin_addr; S_addr is unsigned int * char sin_zero[8]; * }; * */ struct ipstatus_struct { unsigned short ip_channel ; short host_port ; struct tcpip_iosb_struct iosb ; struct dsc$descriptor_s host_desc ; struct sockaddr_in host ; } ; struct SocketParamStruct { unsigned short protocol; unsigned char type; unsigned char family; } ; /* name of the module defined in the WHOIS.CLD file */ extern char CLI_WHOIS[] ; /* routines defined below */ int get_params(); int my_exit(long status); int show_content(struct buffer_struct *buffer); int get_whois( char *server , int port ); int ip_sendline(struct ipstatus_struct *ipstatus, char *data, int size) ; int ip_readline(struct ipstatus_struct *ipstatus, char *data, long max_size) ; int ip_init(struct ipstatus_struct *ipstatus); int ip_connect(struct ipstatus_struct *ipstatus); int ip_disconnect(struct ipstatus_struct *ipstatus); int list_servers( FILE *out_file); struct servers_struct *lookup_asnumber(char *buffer); struct servers_struct *lookup_server(char *buffer); FILE *out_file ; static struct ipstatus_struct ipstatus; struct buffer_struct response ; /****************************************************************/ main () /****************************************************************/ { int status, found_flag ; char *redirect_name, *redirect_ip, *host_tld ; int continue_flag ; char *ptr1, *ptr2 , *ptr3 , *ptr4 ; struct servers_struct *server_info, *server_temp ; struct servers_struct server_arg , server_redirect ; $DESCRIPTOR(server_desc,""); #define HOST_DOMAIN 1 #define HOST_ASNUMBER 2 #define HOST_IPADDR 3 #define HOST_QUOTED 4 #define HOST_OTHER 5 int alpha_host , count, host_type , host_dot, host_quote ; int host_alpha, host_AS, host_num ; char new_server[256], curr_server[256]; char visited_servers[512]; /** first step, get the parameters */ get_params(); /** now, open the output file **/ out_file = fopen( cli_output_str, "w"); if(!out_file) { printf("Error opening output file\n"); my_exit(2); } /* if a /LIST operation, dump the contents and exit */ if(cli_list_present & 1) { list_servers( out_file) ; fclose(out_file); my_exit(1); } ; /** PARSE HOST NAME **/ /** possibilities: ** chocolate.com ** 207.196.233.23 ** AS5880 ** "help" **/ /* Now, take the host name and isolate the TLD * check if ip number or host name (presence of alphabetic character) */ ptr1 = cli_host_name_str ; host_tld = 0 ; host_type = host_dot = host_quote = host_alpha = host_AS = 0 ; host_num = 1 ; server_info = 0 ; while (*ptr1) { if ( *ptr1 == '"' ) host_quote = 1 ; if ( *ptr1 == '.' ) { host_dot = 1 ; host_tld = ptr1; } if ( isalpha(*ptr1)) host_alpha = 1; if ( !isdigit(*ptr1) && (*ptr1 != '.')) host_num = 0 ; if ( isspace(*ptr1)) { host_dot = host_alpha = 0; host_num = 1 ; } *ptr1 = tolower(*ptr1) ; ptr1 ++ ; } if(host_tld) { host_tld ++ ; /* skip to first character after final dot */ ptr2 = host_tld ; while(*ptr2 && !isspace(*ptr2)) ptr2 ++ ; *ptr2 = 0x00; } /* any trailing spaces gone */ if(host_quote) /* remove double quotes */ { ptr3 = ptr4 = cli_host_name_str ; while(*ptr3) { if(*ptr3 != '"') { *ptr4 = *ptr3 ; ptr4 ++ ;} ptr3 ++ ; server_info = 0 ; host_quote = 0 ; } *ptr4 = 0x00; } /*** decision tree ***/ if ( (cli_host_name_str[0] == 'a') &&(cli_host_name_str[1] == 's') &&(isdigit(cli_host_name_str[2])) &&( !host_dot) ) { host_type = HOST_ASNUMBER; host_alpha = 0 ; cli_host_name_str[0] = 'A'; cli_host_name_str[1] = 'S'; server_info = lookup_asnumber(cli_host_name_str); } /** deal with normal domain names **/ else if ( host_alpha && host_dot ) { server_info = lookup_server(host_tld); host_type = HOST_DOMAIN ; } /** deal with IP adress **/ else if (host_num) { host_type = HOST_IPADDR ; server_info = lookup_asnumber("AS1"); /* gets ARIN's server info */ } else { host_type = HOST_OTHER ; server_info = 0; } /** end of decision tree ***/ if( cli_server_present & 1 ) /* override any found servers */ { server_arg.tld = "" ; server_arg.server = cli_server_str ; /* override anything found */ server_arg.country = "" ; server_info = &server_arg ; found_flag = 1 ; } if(!server_info) { fprintf(out_file, "No whois server could be found to resolve: %s\n", cli_host_name_str); fprintf(out_file, "Try http://www.iana.org to locate the autority for the tld\n" ); fprintf(out_file, "and specify it with the /SERVER or /HOST qualifier\n"); my_exit(4); } else if (server_info->server == NONE) { fprintf(out_file, "The tld: %s [%s] doesn't seem to have a whois or http interface\n", host_tld, server_info->country ); fprintf(out_file, "Try http://www.iana.org to locate the autority for this tld:\n"); my_exit(6); } else if (server_info->server == WEB) { fprintf(out_file, "The tld: %s [%s] doesn't seem to have a whois interface\n", host_tld, server_info->country ); fprintf(out_file, "Try the web interface at: %s \n", server_info->http ); my_exit(7); } /******************************************************************** * now we have collected and validated all the info, time to connect to * the whois server and fetch the information */ response.used = 0 ; response.alloc = BUFFER_ALLOC_INIT ; response.data = malloc(response.alloc) ; /* ip_init is now done each time, inside the get_whois loop status = ip_init(&ipstatus); if(status != 1) { fprintf(out_file, "Could not initialise internet connection\n"); my_exit(8); } */ continue_flag = 1 ; /*** */ /*** LOOP UNTIL AUTHORITATIVE RESPONSE RECEIVED */ /*** */ /*** */ while(continue_flag) { response.ptr = response.data ; response.used = 0 ; response.remain = response.alloc ; strcat(visited_servers, server_info->server); strcat(visited_servers, " "); status = get_whois( server_info->server, cli_port_int); if(status != 1) { fprintf(out_file, "WHOIS-E-NOCONNECT Could not get response from server %s\n", server_info->server); fclose(out_file); my_exit(10); } /* now we have the response in response.data, check if there is need to * redirect to another whois server */ new_server[0] = 0x00 ; if(host_type == HOST_DOMAIN) { if( redirect_name = strstr(response.data, "Whois Server:")) { ptr1 = redirect_name ; ptr2 = new_server ; while (*ptr1 && (*ptr1 != ':')) ptr1 ++ ; if(*ptr1) ptr1 ++ ; while (*ptr1 && isspace(*ptr1)) ptr1 ++ ; while (*ptr1 && !isspace(*ptr1)) { *ptr2 = *ptr1 ; ptr2 ++; ptr1 ++; } *ptr2 = 0x00 ; server_redirect.tld = "" ; strcpy(curr_server,new_server); server_redirect.server = curr_server ; server_redirect.country = "" ; server_redirect.http = "" ; } /* end of if Whois Server: was found */ } /* end of if HOST_DOMAIN */ else { if( redirect_ip = strstr(response.data, "OrgID:")) { ptr1 = redirect_ip ; ptr2 = new_server ; while (*ptr1 && (*ptr1 != ':')) ptr1 ++ ; if(*ptr1) ptr1 ++ ; while (*ptr1 && isspace(*ptr1)) ptr1 ++ ; while (*ptr1 && !isspace(*ptr1)) { *ptr2 = toupper(*ptr1) ; ptr2 ++; ptr1 ++; } *ptr2 = 0x00 ; /* now, lookup name into table of reverse lookups to find server */ server_temp = &server_reverse[0] ; /* defined in servers.h */ while( server_temp->tld && strcmp(new_server, server_temp->tld)) { server_temp ++ ; } if(server_temp->tld) { strcpy(new_server,server_temp->server); server_redirect.tld = server_temp->tld ; server_redirect.server = server_temp->server ; server_redirect.country = server_temp->country ; server_redirect.http = server_temp->http ; } else { new_server[0] = 0x00 ; /* redirected to an unknown server*/ /* consider it a dead end */ } } /* end of if OrgID was found */ } /* end of if numeric host */ /** check for loop in server list **/ if(new_server[0] && strstr( visited_servers, new_server )) { fprintf(out_file, "WARNING: redirected to %s which has already been visited\n", new_server ); new_server[0] = 0x00 ; } if( (cli_full_present & 1) || (new_server[0] == 0x00) ) { /** display this transaction **/ fprintf(out_file, "----Server: %s [%s] response for %s\n", server_info->server, server_info->country, cli_host_name_str); show_content(&response); } else { fprintf(out_file, "----Server: %s [%s] redirects to %s\n", server_info->server, server_info->country, new_server); } if( new_server[0] ) { server_info = &server_redirect ; continue_flag = 1 ; /* check here for loop */ } else { continue_flag = 0 ; } } /* end of while continue_flag */ /* zap contents of the response */ fclose(out_file); exit(1); /* no need to use my_exit here */ } /* end of main */ /****************************************************************/ /****************************************************************/ get_whois(char *server, int port) /****************************************************************/ { int status; char host[256]; int host_len, server_len, server_port ; int num_errors = 0 ; char *ptr1 , *ptr2 ; if( !strncmp(server, "rwhois", 6) && !( cli_port_present & 1)) port = 4321 ; ptr1 = server ; while (*ptr1 && (*ptr1 != ':')) { ptr1 ++ ; } server_len = ptr1 - server ; if(*ptr1 == ':') { ptr1 ++ ; port = atoi(ptr1); } ipstatus.host_desc.dsc$a_pointer = server ; ipstatus.host_desc.dsc$w_length = server_len ; ipstatus.host_desc.dsc$b_dtype = DSC$K_DTYPE_T ; ipstatus.host_desc.dsc$b_class = DSC$K_CLASS_S ; ipstatus.host_port = port ; /* add the to end of host_name */ memcpy( host, cli_host_name_str, cli_host_name_len); host_len = cli_host_name_len ; host[host_len] = 0x0D ; host_len ++ ; host[host_len] = 0x0A ; host_len ++ ; host[host_len] = 0x00 ; status = ip_init(&ipstatus); status = ip_connect(&ipstatus); if(!status) { my_exit(12); } status = ip_sendline(&ipstatus, host, host_len ) ; num_errors = 0 ; /* now read the stuff until remote end closes link */ while( (status = ip_readline(&ipstatus, response.ptr, response.remain )) > -1) { if(status == 0) num_errors ++ ; else num_errors = 0 ; if(num_errors >3) break ; response.ptr += status ; response.used += status ; response.remain -= status ; if(response.remain < 512) { response.alloc += 2000 ; response.data = realloc(response.data, response.alloc); response.remain = response.alloc - response.used ; } response.ptr = response.data + response.used ; } /* end of while */ response.ptr = 0x00; status = ip_disconnect(&ipstatus); return(1); } /*** end of get_whois ****/ /****************************************************************/ get_params() /****************************************************************/ { long status; char command_line[264]; char temp_str[24]; $DESCRIPTOR(command_desc,""); $DESCRIPTOR(TEMP_DESC,""); unsigned short temp_len ; unsigned short command_length ; command_desc.dsc$a_pointer = command_line ; command_desc.dsc$w_length = sizeof(command_line); TEMP_DESC.dsc$a_pointer = temp_str; TEMP_DESC.dsc$w_length - sizeof(temp_str); memcpy(command_line,"WHOIS ",6); command_desc.dsc$a_pointer = &command_line[6] ; /* skip "whois " */ command_desc.dsc$w_length -= 6 ; status = lib$get_foreign( &command_desc, 0, &command_length , 0); command_desc.dsc$w_length = command_length + 6 ; command_desc.dsc$a_pointer = command_line ; *(command_desc.dsc$a_pointer + command_desc.dsc$w_length ) = 0x00; status = cli$dcl_parse( &command_desc, &CLI_WHOIS, &lib$get_input, &lib$get_input, 0); if(! (status & 1)) { exit(status | 0x10000000L); /* parse failed */ } cli_list_present = cli$present(&CLI_LIST); cli_output_present = cli$present(&CLI_OUTPUT); status = cli$get_value( &CLI_OUTPUT, &CLI_OUTPUT_DESC, &cli_output_len); if(!(cli_list_present & 1) ) { cli_host_name_present = cli$present(&CLI_HOST_NAME); cli_server_present = cli$present(&CLI_SERVER); cli_host_present = cli$present(&CLI_HOST); cli_full_present = cli$present(&CLI_FULL); cli_brief_present = cli$present(&CLI_BRIEF); cli_port_present = cli$present(&CLI_PORT); status = cli$get_value( &CLI_HOST_NAME, &CLI_HOST_NAME_DESC, &cli_host_name_len); if(cli_server_present & 1) { status = cli$get_value( &CLI_SERVER, &CLI_SERVER_DESC, &cli_server_len); } if(cli_host_present & 1) { status = cli$get_value( &CLI_HOST, &CLI_SERVER_DESC, &cli_server_len); cli_server_present = cli_host_present ; } if(cli_port_present & 1) { status = cli$get_value (&CLI_PORT, &TEMP_DESC, &temp_len); temp_str[temp_len] = 0x00 ; cli_port_int = atoi(temp_str); } else cli_port_int = 43 ; } else { /* set unused variables to null length for a /LIST operation */ cli_host_name_len = 0 ; cli_server_len = 0 ; } /* end of if list_present or else */ CLI_OUTPUT_DESC.dsc$w_length = cli_output_len ; cli_output_str[cli_output_len] = 0x00 ; CLI_HOST_NAME_DESC.dsc$w_length = cli_host_name_len ; CLI_SERVER_DESC.dsc$w_length = cli_server_len ; cli_host_name_str[cli_host_name_len] = 0x00; cli_server_str[cli_server_len] = 0x00; return(1); } /* end of get_params */ /****************************************************************/ /*******************************************************************/ ip_sendline(struct ipstatus_struct *ipstatus, char *data, int size) /*******************************************************************/ { int temp_length, status ; temp_length = size; if(!temp_length) return ; status = sys$qiow(0, /* Event flag */ ipstatus->ip_channel, /* Channel number */ IO$_WRITEVBLK, /* I/O function */ &ipstatus->iosb, /* I/O status block */ 0, 0, data, /* P1 buffer */ temp_length, /* P2 buffer length */ 0, 0, 0, 0); if ((status != SS$_NORMAL) || (ipstatus->iosb.status != SS$_NORMAL)) { fprintf(out_file, "IP_SENDLINE: WRITE to host =>%s<= failed\n QIO status=%d", ipstatus->host_desc.dsc$a_pointer, ipstatus->iosb.status); } } /* end of sendline */ /*******************************************************************/ ip_readline(struct ipstatus_struct *ipstatus, char *data, long max_size) /*******************************************************************/ { int status ; ipstatus->iosb.count = 0 ; status = sys$qiow(0, /* Event flag */ ipstatus->ip_channel, /* Channel number */ IO$_READVBLK, /* I/O function */ &ipstatus->iosb, /* I/O status block */ 0, 0, data, /* P1 buffer */ max_size, /* P2 buffer length */ 0, 0, 0, 0); *(data + ipstatus->iosb.count) = 0x00 ; if( ipstatus->iosb.status == SS$_LINKDISCON) return(-1); else if ((status != SS$_NORMAL) || (ipstatus->iosb.status != SS$_NORMAL )) { fprintf(out_file, "IP_readline: \n QIO status=%d", status ); fprintf(out_file, " IOSB status = %d count=%d\n", ipstatus->iosb.status, ipstatus->iosb.count); return(-1); } return(ipstatus->iosb.count); } /* end of readline */ /*********************************************/ ip_connect(struct ipstatus_struct *ipstatus) /*********************************************/ { #define htons(x) ((unsigned short)((x<<8)|(x>>8))) int status ; struct SocketParamStruct socketParam; /* params used to create socket */ short retlen ; unsigned long bind_command = INETACP$C_TRANS * 256 + INETACP_FUNC$C_GETHOSTBYNAME ; $DESCRIPTOR(acp_command,""); $DESCRIPTOR(response_desc,""); char addr_buff[4]; char buffer[80]; struct itemlst_2 { unsigned short il2_length; unsigned short il2_type ; void *il2_address; } host_address ; /* initialize the socket structure to nulls */ memset( &(ipstatus->host), 0, sizeof(struct sockaddr_in)); /* now, do a bind resolve of the host name */ acp_command.dsc$a_pointer = (void *) &bind_command; acp_command.dsc$w_length = sizeof(bind_command); response_desc.dsc$a_pointer = (void *) &(ipstatus->host.sin_addr) ; response_desc.dsc$w_length = 4 ; /* unsigned long IP address */ retlen = 0 ; strcpy(buffer, ipstatus->host_desc.dsc$a_pointer); ipstatus->host_desc.dsc$a_pointer = buffer ; status = sys$qiow(0,ipstatus->ip_channel, IO$_ACPCONTROL, &ipstatus->iosb,0,0, &acp_command, &ipstatus->host_desc, &retlen, &response_desc, 0,0); if ((status != SS$_NORMAL) || (ipstatus->iosb.status != SS$_NORMAL)) { fprintf(out_file, "%%WHOIS-E-BADSRV, Cannot resolve IP for whois server: %s\n", ipstatus->host_desc.dsc$a_pointer); return(0); } /* fprintf(out_file, "%s translates to %d.%d.%d.%d\n", ipstatus->host_desc.dsc$a_pointer, ipstatus->host.sin_addr.S_un.S_un_b.s_b1, ipstatus->host.sin_addr.S_un.S_un_b.s_b2, ipstatus->host.sin_addr.S_un.S_un_b.s_b3, ipstatus->host.sin_addr.S_un.S_un_b.s_b4); */ /* ipstatus->host.sin_addr is set by above QIO and sin_zero inited to 0s */ /**** connection can now be made ******/ ipstatus->host.sin_family = TCPIP$C_AF_INET; ipstatus->host.sin_port= htons(ipstatus->host_port); socketParam.protocol = TCPIP$C_TCP; socketParam.type = INET_PROTYP$C_STREAM; socketParam.family = AF_INET; status = sys$qiow(0, /* Event flag */ ipstatus->ip_channel,/* Channel number */ IO$_SETMODE, /* I/O function */ &ipstatus->iosb, /* I/O status block */ 0, 0, &socketParam, 0, /* P1 Socket creation parameter */ 0, 0, 0, 0); if ((status != SS$_NORMAL) || (ipstatus->iosb.status != SS$_NORMAL)) { fprintf(out_file, "IP_CONNECT: SETMODE to host =>%s<= failed\n QIO status=", ipstatus->host_desc.dsc$a_pointer); lib$signal(status); fprintf(out_file, " IOSB status ="); lib$signal(ipstatus->iosb.status); return(0); } memset(&host_address, 0, sizeof(host_address)); host_address.il2_length = sizeof( struct sockaddr_in) ; host_address.il2_address = &(ipstatus->host); status = sys$qiow(0,ipstatus->ip_channel, IO$_ACCESS, &ipstatus->iosb,0,0, 0,0,&host_address, 0,0,0); if ((status != SS$_NORMAL) || (ipstatus->iosb.status != SS$_NORMAL)) { fprintf(out_file, "%%WHOIS-E-NOCONNECT, Connection to server %s failed\n", ipstatus->host_desc.dsc$a_pointer); lib$signal(ipstatus->iosb.status); return(0); } return(1); } /* end of ip_connect */ /*******************************************/ ip_disconnect(struct ipstatus_struct *ipstatus) /*******************************************/ { int status ; /* Close the socket (optional). */ status = sys$qiow(3, ipstatus->ip_channel, IO$_DEACCESS , &ipstatus->iosb, 0, 0, 0, 0, 0, 0 , 0, 0); if ((status != SS$_NORMAL) || (ipstatus->iosb.status != SS$_NORMAL)) { fprintf(out_file, "IP_DISCONNECT: DEACCESS host =>%s<= failed\n QIO status=", ipstatus->host_desc.dsc$a_pointer); fprintf(out_file, " IOSB status ="); } status = sys$dassgn(ipstatus->ip_channel) ; return(1); } /* end of ip_disconnect */ /*********************************************/ int ip_init(struct ipstatus_struct *ipstatus) /*********************************************/ { /* Convert short port number from host to network byte order */ int status ; $DESCRIPTOR(TCPIP$DEVICE,"TCPIP$DEVICE"); /* now we assign channel to IP device */ /* this gets re-used if whois searches multiple servers */ status = sys$assign(&TCPIP$DEVICE,&(ipstatus->ip_channel),0,0); if(status != SS$_NORMAL) { fprintf(out_file, "%%WHOIS-E-NODEV, Assign to TCPIP$DEVICE failed, TCPIP services unavailable\n"); return(0); } return(1); } /* end of ip_init */ /****************************************************/ my_exit( long status ) /****************************************************/ /** sets up the exit status so that DCL doesn't display a message ** also, if an odd "status", then first bit of exit status is also ** set to 1 to indicate status. (value of "status" starts at bit 4) **/ { long final_status ; if(out_file) fclose(out_file) ; final_status = 0x10000000L + ( status & 0x00000001L ) + (status * 8L) ; exit(final_status) ; } /* end of my_exit */ /*********************************************************/ int show_content(struct buffer_struct *buffer) /*********************************************************/ { /** this routine outputs the acquired data in packets not exceeding ** a certain size to make it compatible with "PIPE" and not exceed ** bufquota. PIPE's mailbox is 256 bytes wide. **/ char temp , *ptr1, *ptr2 , *ptr3 ; int remain, mysize ; #define SHOWSIZE 256 ptr1 = buffer->data ; remain = buffer->used ; while (remain > 0 ) { if(remain > SHOWSIZE) mysize = SHOWSIZE ; else mysize = remain ; ptr2 = ptr1 + mysize ; temp = *ptr2 ; *ptr2 = 0x00 ; fprintf(out_file, "%s", ptr1 ); *ptr2 = temp ; ptr1 = ptr2 ; remain -= SHOWSIZE ; } /* end of while */ return(1); } /* end of show_content */ /*****************************************************/ list_servers( FILE *out_file) /*****************************************************/ { char *ptr1 ; struct servers_struct *server_info ; fprintf(out_file,"----------- LIST OF WHOIS SERVERS --------%s--\n", whois_version); server_info = &server_array[0] ; /* defined in servers.h */ while( server_info->tld ) { if (server_info->server == NONE ) ptr1 = "" ; else if (server_info->server == WEB ) ptr1 = server_info->http ; else ptr1 = server_info->server ; if(server_info->server != NONE) fprintf(out_file," %-7s %-30s [%s]\n", server_info->tld, ptr1, server_info->country); server_info ++ ; } /* end of while server_info.tld */ fprintf(out_file,"\n\n----------- REVERSE LOOKUPS ---------------\n"); server_info = &server_reverse[0] ; /* defined in servers.h */ while( server_info->tld ) { if (server_info->server == NONE ) ptr1 = "" ; else if (server_info->server == WEB ) ptr1 = server_info->http ; else ptr1 = server_info->server ; if(server_info->server != NONE) fprintf(out_file," %-7s %-30s [%s]\n", server_info->tld, ptr1, server_info->country); server_info ++ ; } /* end of while server_info.tld */ fprintf(out_file,"\n\n--------------------------------------------\n"); return; } /* end of /LIST_servers */ /*****************************************************************/ struct servers_struct *lookup_asnumber(char *buffer) /*****************************************************************/ { char *ptr1; char *authority ; int value, found_flag ; struct asnumber_struct *asnumber ; struct servers_struct *server ; ptr1 = buffer + 2 ; /* skip the "AS" */ value = atoi(ptr1) ; authority = 0 ; /** lookup authority in the asnumber array **/ asnumber = &asnumber_array[0]; while ( asnumber->low ) { if ((value >= asnumber->low) && (value <= asnumber->high)) { authority = asnumber->server ; break ; } asnumber ++ ; } /* end of while */ if(!authority) return(0); /** now lookup the server info in the reverse_array **/ server = &server_reverse[0] ; found_flag = 0; while( server->tld ) { if(! strcmp( authority, server->tld)) { found_flag = 1 ; break; } ; server ++ ; } /* end of while server_info.tld */ if(found_flag) return(server) ; else return(0); } /* end of lookup_asnumber */ /***************************************************/ struct servers_struct *lookup_server(char *buffer) /***************************************************/ { /* buffer points to first character of .tld */ char tld[25] ; char *ptr1 , *ptr2 ; struct servers_struct *server ; int found_flag, count ; ptr1 = tld ; ptr2 = buffer ; count = 1 ; while (*ptr2 && !isspace(*ptr2)) { *ptr1 = *ptr2; count ++ ; if(count >= sizeof(tld)) break ; ptr1 ++ ; ptr2 ++ ; } *ptr1 = 0x00 ; /* now, scan though the servers structure to find the right info */ server = &(server_array[0]) ; /* defined in servers.h */ found_flag = 0 ; while( server->tld ) { if(! strcmp( tld, server->tld)) { found_flag = 1 ; break; } ; server ++ ; } /* end of while server_info.tld */ if(found_flag) return(server); else return(0); } /* end of lookup_server */