forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathifconfig.cpp
More file actions
executable file
·148 lines (118 loc) · 2.95 KB
/
ifconfig.cpp
File metadata and controls
executable file
·148 lines (118 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//
// ifconfig.cpp
//
// $Id: //poco/1.4/Net/samples/download/src/ifconfig.cpp#1 $
//
// This sample demonstrates the (display only) ifconfig-like capabilities
// of the NetworkInterface class (on platforms where it is supported).
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Net/NetworkInterface.h"
#include <iostream>
#ifdef POCO_NET_HAS_INTERFACE
#include "Poco/Path.h"
#include "Poco/Exception.h"
#include "Poco/Net/IPAddress.h"
#include <memory>
using Poco::Path;
using Poco::Exception;
using Poco::Net::IPAddress;
using Poco::Net::NetworkInterface;
int main(int argc, char** argv)
{
if (argc != 1)
{
Path p(argv[0]);
std::cerr << "usage: " << p.getBaseName() << std::endl;
return 1;
}
try
{
const NetworkInterface::Map map = NetworkInterface::map();
for ( NetworkInterface::Map::const_iterator it = map.begin();
it != map.end(); ++it)
{
const NetworkInterface& intf = it->second;
std::string sep("");
std::cout << intf.name() << " [" << intf.index() << "]: ";
std::cout << "<";
if (intf.isUp())
{
std::cout << sep << "UP";
sep = ",";
}
if (intf.isRunning())
{
std::cout << sep << "RUNNING";
sep = ",";
}
if (intf.isLoopback())
{
std::cout << sep << "LOOPBACK";
sep = ",";
}
if (intf.isPointToPoint())
{
std::cout << sep << "P2P";
sep = ",";
}
if (intf.supportsIPv4())
{
std::cout << sep << "IPv4";
sep = ",";
}
if (intf.supportsIPv6())
{
std::cout << sep << "IPv6";
sep = ",";
}
if (intf.supportsBroadcast())
{
std::cout << sep << "BCAST";
sep = ",";
}
if (intf.supportsMulticast())
{
std::cout << sep << "MCAST";
sep = ",";
}
if (!intf.isLoopback())
{
std::cout << sep << std::dec << intf.mtu();
sep = ",";
}
std::cout << ">" << std::endl;
const NetworkInterface::AddressList& ipList = intf.addressList();
NetworkInterface::AddressList::const_iterator ipIt = ipList.begin();
NetworkInterface::AddressList::const_iterator ipEnd = ipList.end();
for (; ipIt != ipEnd; ++ipIt)
{
std::cout << " " << ipIt->get<NetworkInterface::IP_ADDRESS>().toString();
IPAddress addr;
addr = ipIt->get<NetworkInterface::SUBNET_MASK>();
if (!addr.isWildcard()) std::cout << '/' << addr.toString() << " (" << addr.prefixLength() << ')';
addr = ipIt->get<NetworkInterface::BROADCAST_ADDRESS>();
if (!addr.isWildcard()) std::cout << (intf.isPointToPoint() ? " dest " : " bcast ") << addr.toString();
std::cout << std::endl;
}
std::cout << std::endl;
}
}
catch (Exception& exc)
{
std::cerr << exc.displayText() << std::endl;
return 1;
}
return 0;
}
#else // POCO_NET_HAS_INTERFACE
int main(int argc, char** argv)
{
std::cout << "NetworkInterface not supported on this platform." << std::endl;
return 0;
}
#endif // POCO_NET_HAS_INTERFACE