Jpp
18.4.0
the software that should make you happy
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
software
JSystem
getIPaddress.cc
Go to the documentation of this file.
1
#include <string>
2
#include <vector>
3
#include <iostream>
4
#include <iomanip>
5
6
#include "
JSystem/JNetwork.hh
"
7
#include "
Jeep/JParser.hh
"
8
#include "
Jeep/JMessage.hh
"
9
10
namespace
{
11
12
enum
Option_t
{
13
IP_address = 1,
14
IP_subhex,
15
IP_subdec,
16
Hostname
17
};
18
}
19
20
21
/**
22
* \file
23
*
24
* Example program to print IP address.
25
* \author mdejong
26
*/
27
int
main
(
int
argc,
char
* argv[])
28
{
29
using namespace
std;
30
using namespace
JPP;
31
32
string
host_name;
33
int
option;
34
35
try
{
36
37
JParser<>
zap(
"Example program to print IP address."
);
38
39
zap[
'H'
] =
make_field
(host_name) =
"localhost"
;
40
zap[
'O'
] =
make_field
(option,
"option "
41
<< IP_address <<
" -> IP address; "
42
<< IP_subhex <<
" -> IP sub-address (hex); "
43
<< IP_subdec <<
" -> IP sub-address (dec); "
44
<< Hostname <<
" -> host name"
) = IP_address, IP_subhex, IP_subdec, Hostname;
45
46
zap(argc, argv);
47
}
48
catch
(
const
exception &error) {
49
FATAL
(error.what() << endl);
50
}
51
52
int
ip =
getIPnumber
(host_name);
53
54
switch
(option) {
55
56
case
IP_address:
57
cout <<
getIPaddress
(ip) << endl;
return
0;
58
59
case
IP_subhex:
60
cout << hex <<
getSubaddress
(ip) << endl;
return
0;
61
62
case
IP_subdec:
63
cout << dec <<
getSubaddress
(ip) << endl;
return
0;
64
65
case
Hostname:
66
cout << dec <<
getHostname
(ip) << endl;
return
0;
67
68
default
:
69
FATAL
(
"Invalid option "
<< option << endl);
70
}
71
}
JSYSTEM::getIPnumber
int getIPnumber(const std::string &host_name)
Get IP number.
Definition:
JNetwork.hh:117
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1514
main
int main(int argc, char *argv[])
Definition:
Main.cc:15
JSYSTEM::getIPaddress
std::string getIPaddress(const int ip)
Get IP address (decimal-dot notation).
Definition:
JNetwork.hh:154
JSYSTEM::getSubaddress
unsigned short getSubaddress(const int ip)
Get host identifier within network.
Definition:
JNetwork.hh:190
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition:
JParser.hh:1989
Option_t
Option_t
Definition:
getIPaddress.cc:12
JMessage.hh
General purpose messaging.
JSYSTEM::getHostname
std::string getHostname()
Get host name.
Definition:
JNetwork.hh:77
FATAL
#define FATAL(A)
Definition:
JMessage.hh:67
JParser.hh
Utility class to parse command line options.
JNetwork.hh
Hostname and IP address functions.
Generated by
1.8.5