#include #include #include #include #include "JSystem/JNetwork.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { enum Option_t { IP_address = 1, IP_subhex, IP_subdec, Hostname }; } /** * \file * * Example program to print IP address. * \author mdejong */ int main(int argc, char* argv[]) { using namespace std; using namespace JPP; string host_name; int option; try { JParser<> zap("Example program to print IP address."); zap['H'] = make_field(host_name) = "localhost"; zap['O'] = make_field(option, "option " << IP_address << " -> IP address; " << IP_subhex << " -> IP sub-address (hex); " << IP_subdec << " -> IP sub-address (dec); " << Hostname << " -> host name") = IP_address, IP_subhex, IP_subdec, Hostname; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } int ip = getIPnumber(host_name); switch (option) { case IP_address: cout << getIPaddress(ip) << endl; return 0; case IP_subhex: cout << hex << getSubaddress(ip) << endl; return 0; case IP_subdec: cout << dec << getSubaddress(ip) << endl; return 0; case Hostname: cout << dec << getHostname(ip) << endl; return 0; default: FATAL("Invalid option " << option << endl); } }