fixes bug where priorities where lost when force-rechecking.
[libtorrent.git] / examples / enum_if.cpp
blobe2e341e7bcf5c5c071c67845840a73fd4124f3ac
1 /*
3 Copyright (c) 2008, Arvid Norberg
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
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>
36 #include <vector>
37 #include <iomanip>
39 using namespace libtorrent;
41 int main()
43 io_service ios;
44 error_code ec;
46 address local = guess_local_address(ios);
47 std::cout << "Local address: " << local << std::endl;
49 address def_gw = get_default_gateway(ios, ec);
50 if (ec)
52 std::cerr << ec.message() << std::endl;
53 return 1;
55 std::cout << "Default gateway: " << def_gw << std::endl;
57 std::cout << "=========== Routes ===========\n";
58 std::vector<ip_route> routes = enum_routes(ios, ec);
59 if (ec)
61 std::cerr << ec.message() << std::endl;
62 return 1;
65 std::cout << std::setiosflags(std::ios::left)
66 << std::setw(18) << "destination"
67 << std::setw(18) << "netmask"
68 << std::setw(35) << "gateway"
69 << "interface name"
70 << std::endl;
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
79 << i->name
80 << std::endl;
83 std::cout << "========= Interfaces =========\n";
85 std::vector<ip_interface> const& net = enum_net_interfaces(ios, ec);
86 if (ec)
88 std::cerr << ec.message() << std::endl;
89 return 1;
92 std::cout << std::setiosflags(std::ios::left)
93 << std::setw(35) << "address"
94 << std::setw(18) << "netmask"
95 << std::setw(18) << "name"
96 << "flags"
97 << std::endl;
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 ":"")
110 << std::endl;