1 /*****************************************************************
3 | Neptune Utilities - Network Configuration Dump
5 | (c) 2001-2005 Gilles Boccon-Gibod
6 | Author: Gilles Boccon-Gibod (bok@bok.net)
8 ****************************************************************/
10 /*----------------------------------------------------------------------
12 +---------------------------------------------------------------------*/
13 #include "NptConfig.h"
17 #if defined(NPT_CONFIG_HAVE_STDLIB_H)
21 #if defined(NPT_CONFIG_HAVE_STRING_H)
25 #if defined(NPT_CONFIG_HAVE_STDIO_H)
30 /*----------------------------------------------------------------------
32 +---------------------------------------------------------------------*/
34 /*----------------------------------------------------------------------
36 +---------------------------------------------------------------------*/
38 PrintUsageAndExit(void)
41 "usage: NetConfig\n");
45 /*----------------------------------------------------------------------
47 +---------------------------------------------------------------------*/
49 PrintFlags(NPT_Flags flags
)
51 if (flags
& NPT_NETWORK_INTERFACE_FLAG_LOOPBACK
) {
54 if (flags
& NPT_NETWORK_INTERFACE_FLAG_PROMISCUOUS
) {
55 printf("PROMISCUOUS ");
57 if (flags
& NPT_NETWORK_INTERFACE_FLAG_BROADCAST
) {
60 if (flags
& NPT_NETWORK_INTERFACE_FLAG_MULTICAST
) {
63 if (flags
& NPT_NETWORK_INTERFACE_FLAG_POINT_TO_POINT
) {
64 printf("POINT-TO-POINT ");
68 /*----------------------------------------------------------------------
70 +---------------------------------------------------------------------*/
72 main(int argc
, char**)
79 NPT_List
<NPT_NetworkInterface
*> interfaces
;
80 NPT_Result result
= NPT_NetworkInterface::GetNetworkInterfaces(interfaces
);
81 if (NPT_FAILED(result
)) {
82 printf("GetNetworkInterfaces() failed\n");
85 NPT_List
<NPT_NetworkInterface
*>::Iterator iface
= interfaces
.GetFirstItem();
86 unsigned int index
= 0;
88 printf("Interface %d: -------------------------------------\n", index
);
89 printf(" name = %s\n", (*iface
)->GetName().GetChars());
90 printf(" flags = %x [ ", (*iface
)->GetFlags());
91 PrintFlags((*iface
)->GetFlags());
93 printf(" mac = %s (type=%d)\n", (*iface
)->GetMacAddress().ToString().GetChars(), (*iface
)->GetMacAddress().GetType());
95 // print all addresses
96 NPT_List
<NPT_NetworkInterfaceAddress
>::Iterator nwifaddr
=
97 (*iface
)->GetAddresses().GetFirstItem();
98 unsigned int addr_index
= 0;
100 printf(" address %d:\n", addr_index
);
101 printf(" primary address = ");
102 printf("%s\n", nwifaddr
->GetPrimaryAddress().ToString().GetChars());
103 if ((*iface
)->GetFlags() & NPT_NETWORK_INTERFACE_FLAG_BROADCAST
) {
104 printf(" broadcast address = ");
105 printf("%s\n", nwifaddr
->GetBroadcastAddress().ToString().GetChars());
107 if ((*iface
)->GetFlags() & NPT_NETWORK_INTERFACE_FLAG_POINT_TO_POINT
) {
108 printf(" destination address = ");
109 printf("%s\n", nwifaddr
->GetDestinationAddress().ToString().GetChars());
111 printf(" netmask = ");
112 printf("%s\n", nwifaddr
->GetNetMask().ToString().GetChars());