From c04dcc2e7d834218ef2d4194331e383402495ae1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 10 Apr 2024 20:07:22 +0200 Subject: Adding upstream version 2:20.4+dfsg. Signed-off-by: Daniel Baumann --- .../Neptune/Source/Apps/NetConfig/NetConfig.cpp | 126 +++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 lib/libUPnP/Neptune/Source/Apps/NetConfig/NetConfig.cpp (limited to 'lib/libUPnP/Neptune/Source/Apps/NetConfig/NetConfig.cpp') diff --git a/lib/libUPnP/Neptune/Source/Apps/NetConfig/NetConfig.cpp b/lib/libUPnP/Neptune/Source/Apps/NetConfig/NetConfig.cpp new file mode 100644 index 0000000..072b49b --- /dev/null +++ b/lib/libUPnP/Neptune/Source/Apps/NetConfig/NetConfig.cpp @@ -0,0 +1,126 @@ +/***************************************************************** +| +| Neptune Utilities - Network Configuration Dump +| +| (c) 2001-2005 Gilles Boccon-Gibod +| Author: Gilles Boccon-Gibod (bok@bok.net) +| + ****************************************************************/ + +/*---------------------------------------------------------------------- +| includes ++---------------------------------------------------------------------*/ +#include "NptConfig.h" +#include "Neptune.h" +#include "NptDebug.h" + +#if defined(NPT_CONFIG_HAVE_STDLIB_H) +#include +#endif + +#if defined(NPT_CONFIG_HAVE_STRING_H) +#include +#endif + +#if defined(NPT_CONFIG_HAVE_STDIO_H) +#include +#endif + + +/*---------------------------------------------------------------------- +| globals ++---------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------- +| PrintUsageAndExit ++---------------------------------------------------------------------*/ +static void +PrintUsageAndExit(void) +{ + fprintf(stderr, + "usage: NetConfig\n"); + exit(1); +} + +/*---------------------------------------------------------------------- +| PrintFlags ++---------------------------------------------------------------------*/ +static void +PrintFlags(NPT_Flags flags) +{ + if (flags & NPT_NETWORK_INTERFACE_FLAG_LOOPBACK) { + printf("LOOPBACK "); + } + if (flags & NPT_NETWORK_INTERFACE_FLAG_PROMISCUOUS) { + printf("PROMISCUOUS "); + } + if (flags & NPT_NETWORK_INTERFACE_FLAG_BROADCAST) { + printf("BROADCAST "); + } + if (flags & NPT_NETWORK_INTERFACE_FLAG_MULTICAST) { + printf("MULTICAST "); + } + if (flags & NPT_NETWORK_INTERFACE_FLAG_POINT_TO_POINT) { + printf("POINT-TO-POINT "); + } +} + +/*---------------------------------------------------------------------- +| main ++---------------------------------------------------------------------*/ +int +main(int argc, char**) +{ + // check command line + if (argc < 1) { + PrintUsageAndExit(); + } + + NPT_List interfaces; + NPT_Result result = NPT_NetworkInterface::GetNetworkInterfaces(interfaces); + if (NPT_FAILED(result)) { + printf("GetNetworkInterfaces() failed\n"); + return 0; + } + NPT_List::Iterator iface = interfaces.GetFirstItem(); + unsigned int index = 0; + while (iface) { + printf("Interface %d: -------------------------------------\n", index); + printf(" name = %s\n", (*iface)->GetName().GetChars()); + printf(" flags = %x [ ", (*iface)->GetFlags()); + PrintFlags((*iface)->GetFlags()); + printf("]\n"); + printf(" mac = %s (type=%d)\n", (*iface)->GetMacAddress().ToString().GetChars(), (*iface)->GetMacAddress().GetType()); + + // print all addresses + NPT_List::Iterator nwifaddr = + (*iface)->GetAddresses().GetFirstItem(); + unsigned int addr_index = 0; + while (nwifaddr) { + printf(" address %d:\n", addr_index); + printf(" primary address = "); + printf("%s\n", nwifaddr->GetPrimaryAddress().ToString().GetChars()); + if ((*iface)->GetFlags() & NPT_NETWORK_INTERFACE_FLAG_BROADCAST) { + printf(" broadcast address = "); + printf("%s\n", nwifaddr->GetBroadcastAddress().ToString().GetChars()); + } + if ((*iface)->GetFlags() & NPT_NETWORK_INTERFACE_FLAG_POINT_TO_POINT) { + printf(" destination address = "); + printf("%s\n", nwifaddr->GetDestinationAddress().ToString().GetChars()); + } + printf(" netmask = "); + printf("%s\n", nwifaddr->GetNetMask().ToString().GetChars()); + ++nwifaddr; + ++addr_index; + } + + ++iface; + ++index; + } + + return 0; +} + + + + -- cgit v1.2.3