diff --git a/src/bin/network/Jamfile b/src/bin/network/Jamfile index 854037362b..236ef56a6b 100644 --- a/src/bin/network/Jamfile +++ b/src/bin/network/Jamfile @@ -18,4 +18,4 @@ SubInclude HAIKU_TOP src bin network route ; SubInclude HAIKU_TOP src bin network telnet ; SubInclude HAIKU_TOP src bin network telnetd ; SubInclude HAIKU_TOP src bin network traceroute ; - +SubInclude HAIKU_TOP src bin network tunconfig ; diff --git a/src/bin/network/tunconfig/Jamfile b/src/bin/network/tunconfig/Jamfile new file mode 100644 index 0000000000..34ef84f6c9 --- /dev/null +++ b/src/bin/network/tunconfig/Jamfile @@ -0,0 +1,19 @@ +SubDir HAIKU_TOP src bin network tunconfig ; + +UsePrivateKernelHeaders ; +UsePrivateHeaders net ; +UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared libppp + headers ] : true ; +UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared + libkernelppp headers ] : true ; + +BinCommand tunconfig : + tunconfig.cpp + : + be libppp.a [ TargetLibsupc++ ] libbsd.so $(TARGET_NETWORK_LIBS) +; + +# Installation +HaikuInstall install-tun + : /boot/home/config/non-packaged/bin + : tunconfig ; diff --git a/src/bin/network/tunconfig/tunconfig.cpp b/src/bin/network/tunconfig/tunconfig.cpp new file mode 100644 index 0000000000..5005d61e70 --- /dev/null +++ b/src/bin/network/tunconfig/tunconfig.cpp @@ -0,0 +1,76 @@ +/* + * Copyright 2006-2019, Haiku, Inc. All rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Alexander von Gluck IV + */ + + +#include +#include + +#include +#include + + +static +status_t +print_help() +{ + fprintf(stderr, "tunconfig\n"); + fprintf(stderr, "With tunconfig you can create and manage tun/tap devices.\n"); + fprintf(stderr, "Usage:\n"); + fprintf(stderr, " tunconfig show | -a\n"); + fprintf(stderr, " tunconfig init \n"); + fprintf(stderr, " tunconfig create \n"); + fprintf(stderr, " tunconfig delete \n"); + fprintf(stderr, " tunconfig details \n"); + fprintf(stderr, "\t must be an interface description file\n"); + + return -1; +} + + +static +status_t +show_interface(const char* name) +{ + printf("%s\n", name); + return B_OK; +} + + +static +status_t +show_all() +{ + BNetworkRoster& roster = BNetworkRoster::Default(); + + BNetworkInterface interface; + uint32 cookie = 0; + + while (roster.GetNextInterface(&cookie, interface) == B_OK) { + BNetworkAddress linkAddress; + status_t status = interface.GetHardwareAddress(linkAddress); + if (status == B_OK && linkAddress.LinkLevelType() == IFT_TUN) + show_interface(interface.Name()); + } + return B_OK; +} + + +int +main(int argc, char *argv[]) +{ + if (argc == 2) { + if (!strcmp(argv[1], "show") || !strcmp(argv[1], "-a")) + return show_all(); + else + return print_help(); + } else { + return print_help(); + } + + return 0; +}