forked from premiere/premiere-libtorrent
replaced iostream in example
This commit is contained in:
parent
31bbfee895
commit
e5e1bca254
|
@ -30,12 +30,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <libtorrent/enum_net.hpp>
|
#include <libtorrent/enum_net.hpp>
|
||||||
#include <libtorrent/socket.hpp>
|
#include <libtorrent/socket.hpp>
|
||||||
#include <libtorrent/broadcast_socket.hpp>
|
#include <libtorrent/broadcast_socket.hpp>
|
||||||
#include <vector>
|
|
||||||
#include <iomanip>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
|
|
||||||
|
@ -43,73 +41,60 @@ int main()
|
||||||
{
|
{
|
||||||
io_service ios;
|
io_service ios;
|
||||||
error_code ec;
|
error_code ec;
|
||||||
|
|
||||||
address local = guess_local_address(ios);
|
address local = guess_local_address(ios);
|
||||||
std::cout << "Local address: " << local << std::endl;
|
printf("Local address: %s\n", local.to_string(ec).c_str());
|
||||||
|
|
||||||
address def_gw = get_default_gateway(ios, ec);
|
address def_gw = get_default_gateway(ios, ec);
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
std::cerr << ec.message() << std::endl;
|
fprintf(stderr, "%s\n", ec.message().c_str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
std::cout << "Default gateway: " << def_gw << std::endl;
|
|
||||||
|
|
||||||
std::cout << "=========== Routes ===========\n";
|
printf("Default gateway: %s\n", def_gw.to_string(ec).c_str());
|
||||||
|
|
||||||
|
printf("=========== Routes ===========\n");
|
||||||
std::vector<ip_route> routes = enum_routes(ios, ec);
|
std::vector<ip_route> routes = enum_routes(ios, ec);
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
std::cerr << ec.message() << std::endl;
|
printf("%s\n", ec.message().c_str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << std::setiosflags(std::ios::left)
|
printf("%-18s%-18s%-35sinterface name\n", "destination", "network", "gateway");
|
||||||
<< std::setw(18) << "destination"
|
|
||||||
<< std::setw(18) << "netmask"
|
|
||||||
<< std::setw(35) << "gateway"
|
|
||||||
<< "interface name"
|
|
||||||
<< std::endl;
|
|
||||||
|
|
||||||
for (std::vector<ip_route>::const_iterator i = routes.begin()
|
for (std::vector<ip_route>::const_iterator i = routes.begin()
|
||||||
, end(routes.end()); i != end; ++i)
|
, end(routes.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
std::cout << std::setiosflags(std::ios::left)
|
printf("%-18s%-18s%-35s%s\n"
|
||||||
<< std::setw(18) << i->destination
|
, i->destination.to_string(ec).c_str()
|
||||||
<< std::setw(18) << i->netmask
|
, i->netmask.to_string(ec).c_str()
|
||||||
<< std::setw(35) << i->gateway
|
, i->gateway.to_string(ec).c_str()
|
||||||
<< i->name
|
, i->name);
|
||||||
<< std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "========= Interfaces =========\n";
|
printf("========= Interfaces =========\n");
|
||||||
|
|
||||||
std::vector<ip_interface> const& net = enum_net_interfaces(ios, ec);
|
std::vector<ip_interface> const& net = enum_net_interfaces(ios, ec);
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
std::cerr << ec.message() << std::endl;
|
printf("%s\n", ec.message().c_str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << std::setiosflags(std::ios::left)
|
printf("%-18s%-18s%-35sflags\n", "address", "netmask", "name");
|
||||||
<< std::setw(35) << "address"
|
|
||||||
<< std::setw(18) << "netmask"
|
|
||||||
<< std::setw(18) << "name"
|
|
||||||
<< "flags"
|
|
||||||
<< std::endl;
|
|
||||||
|
|
||||||
for (std::vector<ip_interface>::const_iterator i = net.begin()
|
for (std::vector<ip_interface>::const_iterator i = net.begin()
|
||||||
, end(net.end()); i != end; ++i)
|
, end(net.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
std::cout << std::setiosflags(std::ios::left)
|
printf("%-18s%-18s%-35s%s%s%s\n"
|
||||||
<< std::setw(35) << i->interface_address
|
, i->interface_address.to_string(ec).c_str()
|
||||||
<< std::setw(18) << i->netmask
|
, i->netmask.to_string(ec).c_str()
|
||||||
<< std::setw(18) << i->name
|
, i->name
|
||||||
<< (is_multicast(i->interface_address)?"multicast ":"")
|
, (is_multicast(i->interface_address)?"multicast ":"")
|
||||||
<< (is_local(i->interface_address)?"local ":"")
|
, (is_local(i->interface_address)?"local ":"")
|
||||||
<< (is_loopback(i->interface_address)?"loopback ":"")
|
, (is_loopback(i->interface_address)?"loopback ":"")
|
||||||
|
);
|
||||||
<< std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue