1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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 <stdlib.h>
#endif
#if defined(NPT_CONFIG_HAVE_STRING_H)
#include <string.h>
#endif
#if defined(NPT_CONFIG_HAVE_STDIO_H)
#include <stdio.h>
#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<NPT_NetworkInterface*> interfaces;
NPT_Result result = NPT_NetworkInterface::GetNetworkInterfaces(interfaces);
if (NPT_FAILED(result)) {
printf("GetNetworkInterfaces() failed\n");
return 0;
}
NPT_List<NPT_NetworkInterface*>::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<NPT_NetworkInterfaceAddress>::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;
}
|