00001 /*****************************************************************************\ 00002 * * 00003 * Name : check_address * 00004 * Author : Chris Koeritz * 00005 * * 00006 ******************************************************************************* 00007 * Copyright (c) 2000-$now By Author. This program is free software; you can * 00008 * redistribute it and/or modify it under the terms of the GNU General Public * 00009 * License as published by the Free Software Foundation; either version 2 of * 00010 * the License or (at your option) any later version. This is online at: * 00011 * http://www.fsf.org/copyleft/gpl.html * 00012 * Please send any updates to: fred@gruntose.com * 00013 \*****************************************************************************/ 00014 00015 #include <basis/byte_array.h> 00016 #include <opsystem/byte_filer.h> 00017 #include <loggers/console_logger.h> 00018 #include <opsystem/filename.h> 00019 #include <data_struct/static_memory_gremlin.h> 00020 #include <sockets/address.h> 00021 #include <sockets/tcpip_stack.h> 00022 00023 #include <stdio.h> 00024 00025 HOOPLE_STARTUP_CODE; 00026 00027 console_logger out; 00028 #define LOG(to_print) EMERGENCY_LOG(out, to_print) 00029 00031 00032 bool check_hostname(const istring &host) 00033 { 00034 tcpip_stack stack; 00035 istring full_name; 00036 byte_array addr = stack.full_resolve(host, full_name); 00037 // if the address has any length, we are successful in finding the name. 00038 if (!addr.length()) { 00039 // failed. 00040 LOG(host + ": host is not listed in DNS or WINS!"); 00041 return false; 00042 } 00043 return true; 00044 } 00045 00046 int main(int argc, char *argv[]) 00047 { 00048 if (argc < 2) { 00049 out.log(filename(argv[0]).rootname() + " usage:\n\ 00050 The first parameter must be a host name or IP address that will be\n\ 00051 checked for reachability.\n"); 00052 return 1; 00053 } 00054 istring parm = argv[1]; 00055 bool happy = false; 00056 if (internet_address::valid_address(parm)) { 00057 // this looks like an IP address, so we'll assume they're hip about it. 00058 return 0; 00059 } else { 00060 // more like a hostname here. see if we can find its address. 00061 happy = check_hostname(parm); 00062 } 00063 00064 if (happy) { 00065 LOG(istring("found ") + parm + " successfully."); 00066 } 00067 00068 // if happy is okay, then we return zero. 00069 return !happy; 00070 } 00071 00072 #ifdef __BUILD_STATIC_APPLICATION__ 00073 // static dependencies found by buildor_gen_deps.sh: 00074 #include <basis/array.cpp> 00075 #include <basis/byte_array.cpp> 00076 #include <basis/callstack_tracker.cpp> 00077 #include <basis/chaos.cpp> 00078 #include <basis/convert_utf.cpp> 00079 #include <basis/definitions.cpp> 00080 #include <basis/earth_time.cpp> 00081 #include <basis/guards.cpp> 00082 #include <basis/istring.cpp> 00083 #include <basis/log_base.cpp> 00084 #include <basis/memory_checker.cpp> 00085 #include <basis/mutex.cpp> 00086 #include <basis/object_base.cpp> 00087 #include <basis/outcome.cpp> 00088 #include <basis/packable.cpp> 00089 #include <basis/portable.cpp> 00090 #include <basis/sequence.cpp> 00091 #include <basis/set.cpp> 00092 #include <basis/utility.cpp> 00093 #include <basis/version_record.cpp> 00094 #include <data_struct/amorph.cpp> 00095 #include <data_struct/bit_vector.cpp> 00096 #include <data_struct/byte_hasher.cpp> 00097 #include <data_struct/configurator.cpp> 00098 #include <data_struct/hash_table.cpp> 00099 #include <data_struct/pointer_hash.cpp> 00100 #include <data_struct/stack.cpp> 00101 #include <data_struct/static_memory_gremlin.cpp> 00102 #include <data_struct/string_hash.cpp> 00103 #include <data_struct/string_hasher.cpp> 00104 #include <data_struct/string_table.cpp> 00105 #include <data_struct/symbol_table.cpp> 00106 #include <data_struct/table_configurator.cpp> 00107 #include <loggers/console_logger.cpp> 00108 #include <loggers/file_logger.cpp> 00109 #include <loggers/locked_logger.cpp> 00110 #include <loggers/null_logger.cpp> 00111 #include <loggers/program_wide_logger.cpp> 00112 #include <opsystem/byte_filer.cpp> 00113 #include <opsystem/command_line.cpp> 00114 #include <opsystem/critical_events.cpp> 00115 #include <opsystem/directory.cpp> 00116 #include <opsystem/filename.cpp> 00117 #include <opsystem/ini_config.cpp> 00118 #include <opsystem/ini_parser.cpp> 00119 #include <opsystem/path_configuration.cpp> 00120 #include <opsystem/rendezvous.cpp> 00121 #include <sockets/address_base.cpp> 00122 #include <sockets/address.cpp> 00123 #include <sockets/imp_sockets.cpp> 00124 #include <sockets/machine_uid.cpp> 00125 #include <sockets/tcpip_stack.cpp> 00126 #include <textual/byte_format.cpp> 00127 #include <textual/parser_bits.cpp> 00128 #include <textual/string_manipulation.cpp> 00129 #include <textual/tokenizer.cpp> 00130 #endif // __BUILD_STATIC_APPLICATION__ 00131
1.5.1