3 Copyright (c) 2008, Arvid Norberg
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the distribution.
15 * Neither the name of the author nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 POSSIBILITY OF SUCH DAMAGE.
33 #include <libtorrent/enum_net.hpp>
34 #include <libtorrent/socket.hpp>
35 #include <libtorrent/broadcast_socket.hpp>
39 using namespace libtorrent
;
46 address local
= guess_local_address(ios
);
47 std::cout
<< "Local address: " << local
<< std::endl
;
49 address def_gw
= get_default_gateway(ios
, ec
);
52 std::cerr
<< ec
.message() << std::endl
;
55 std::cout
<< "Default gateway: " << def_gw
<< std::endl
;
57 std::cout
<< "=========== Routes ===========\n";
58 std::vector
<ip_route
> routes
= enum_routes(ios
, ec
);
61 std::cerr
<< ec
.message() << std::endl
;
65 std::cout
<< std::setiosflags(std::ios::left
)
66 << std::setw(18) << "destination"
67 << std::setw(18) << "netmask"
68 << std::setw(35) << "gateway"
72 for (std::vector
<ip_route
>::const_iterator i
= routes
.begin()
73 , end(routes
.end()); i
!= end
; ++i
)
75 std::cout
<< std::setiosflags(std::ios::left
)
76 << std::setw(18) << i
->destination
77 << std::setw(18) << i
->netmask
78 << std::setw(35) << i
->gateway
83 std::cout
<< "========= Interfaces =========\n";
85 std::vector
<ip_interface
> const& net
= enum_net_interfaces(ios
, ec
);
88 std::cerr
<< ec
.message() << std::endl
;
92 std::cout
<< std::setiosflags(std::ios::left
)
93 << std::setw(35) << "address"
94 << std::setw(18) << "netmask"
95 << std::setw(18) << "name"
99 for (std::vector
<ip_interface
>::const_iterator i
= net
.begin()
100 , end(net
.end()); i
!= end
; ++i
)
102 std::cout
<< std::setiosflags(std::ios::left
)
103 << std::setw(35) << i
->interface_address
104 << std::setw(18) << i
->netmask
105 << std::setw(18) << i
->name
106 << (is_multicast(i
->interface_address
)?"multicast ":"")
107 << (is_local(i
->interface_address
)?"local ":"")
108 << (is_loopback(i
->interface_address
)?"loopback ":"")