@@ -29,6 +29,7 @@ const char* GetAdapterType(ULONG IfType)
29
29
}
30
30
}
31
31
32
+ // Convert the physical adapter address to a human-readable hex format
32
33
std::string GetMacAddress (BYTE* addr, ULONG length)
33
34
{
34
35
std::string macAddress;
@@ -46,6 +47,8 @@ std::string GetMacAddress(BYTE* addr, ULONG length)
46
47
return macAddress;
47
48
}
48
49
50
+ // Displays adapter info similar to ipconfig
51
+ // Returns true if IPv6 address is found
49
52
bool DumpIPv6Config ()
50
53
{
51
54
// Check if IPv6 is supported
@@ -82,14 +85,15 @@ bool DumpIPv6Config()
82
85
PIP_ADAPTER_ADDRESSES pCurrAddresses = pAddresses;
83
86
while (pCurrAddresses)
84
87
{
85
- // Print the output similar to ipconfig
86
88
std::wcout << GetAdapterType (pCurrAddresses->IfType ) << " adapter " << pCurrAddresses->FriendlyName << " :" << std::endl << std::endl;
87
89
std::wcout << " Media State . . . . . . . . . . . : " << (pCurrAddresses->OperStatus == IfOperStatusUp ? " Media disconnected" : " Media connected" ) << std::endl;
88
90
std::wcout << " Connection-specific DNS Suffix . : " << pCurrAddresses->DnsSuffix << std::endl;
89
91
std::wcout << " Description . . . . . . . . . . . : " << pCurrAddresses->Description << std::endl;
90
92
std::cout << " Physical Address. . . . . . . . . : " << GetMacAddress (pCurrAddresses->PhysicalAddress , pCurrAddresses->PhysicalAddressLength ) << std::endl;
91
93
std::wcout << " Adapter ID (GUID) . . . . . . . . : " << pCurrAddresses->AdapterName << std::endl;
92
94
95
+ // Assign luid to the loopback adapter so we can
96
+ // later assign the IPv6 address to it
93
97
if (pCurrAddresses->IfType == IF_TYPE_SOFTWARE_LOOPBACK)
94
98
{
95
99
luid = pCurrAddresses->Luid ;
@@ -174,6 +178,7 @@ bool AddIPv6AddressToAdapter(const NET_LUID& luid, const char* ipv6Address, cons
174
178
{
175
179
// REF: https://learn.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-createunicastipaddressentry
176
180
181
+ // Remove the address if it already exists. Illustration purposes really, simplifies the sample
177
182
DeleteIPv6AddressFromAdapter (luid, ipv6Address, prefixLength);
178
183
179
184
MIB_UNICASTIPADDRESS_ROW ipRow;
@@ -220,7 +225,7 @@ int main()
220
225
}
221
226
222
227
// Assign a new IPv6 address to the loopback adapter
223
- // Note that
228
+ // Note that luid is assigned in DumpIPv6Config()
224
229
const char * ipv6Address = " 2001:db8::1234" ; // Example IPv6 address
225
230
const char * prefixLength = " 64" ; // Example prefix length
226
231
0 commit comments