Skip to content

Commit ee6eeb6

Browse files
authored
Update ConfigureIPv6.cpp
Added some comments
1 parent 9a407e3 commit ee6eeb6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

IPHelper/ConfigureIPv6.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const char* GetAdapterType(ULONG IfType)
2929
}
3030
}
3131

32+
// Convert the physical adapter address to a human-readable hex format
3233
std::string GetMacAddress(BYTE* addr, ULONG length)
3334
{
3435
std::string macAddress;
@@ -46,6 +47,8 @@ std::string GetMacAddress(BYTE* addr, ULONG length)
4647
return macAddress;
4748
}
4849

50+
// Displays adapter info similar to ipconfig
51+
// Returns true if IPv6 address is found
4952
bool DumpIPv6Config()
5053
{
5154
// Check if IPv6 is supported
@@ -82,14 +85,15 @@ bool DumpIPv6Config()
8285
PIP_ADAPTER_ADDRESSES pCurrAddresses = pAddresses;
8386
while (pCurrAddresses)
8487
{
85-
// Print the output similar to ipconfig
8688
std::wcout << GetAdapterType(pCurrAddresses->IfType) << " adapter " << pCurrAddresses->FriendlyName << ":" << std::endl << std::endl;
8789
std::wcout << " Media State . . . . . . . . . . . : " << (pCurrAddresses->OperStatus == IfOperStatusUp ? "Media disconnected" : "Media connected") << std::endl;
8890
std::wcout << " Connection-specific DNS Suffix . : " << pCurrAddresses->DnsSuffix << std::endl;
8991
std::wcout << " Description . . . . . . . . . . . : " << pCurrAddresses->Description << std::endl;
9092
std::cout << " Physical Address. . . . . . . . . : " << GetMacAddress(pCurrAddresses->PhysicalAddress, pCurrAddresses->PhysicalAddressLength) << std::endl;
9193
std::wcout << " Adapter ID (GUID) . . . . . . . . : " << pCurrAddresses->AdapterName << std::endl;
9294

95+
// Assign luid to the loopback adapter so we can
96+
// later assign the IPv6 address to it
9397
if (pCurrAddresses->IfType == IF_TYPE_SOFTWARE_LOOPBACK)
9498
{
9599
luid = pCurrAddresses->Luid;
@@ -174,6 +178,7 @@ bool AddIPv6AddressToAdapter(const NET_LUID& luid, const char* ipv6Address, cons
174178
{
175179
// REF: https://learn.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-createunicastipaddressentry
176180

181+
// Remove the address if it already exists. Illustration purposes really, simplifies the sample
177182
DeleteIPv6AddressFromAdapter(luid, ipv6Address, prefixLength);
178183

179184
MIB_UNICASTIPADDRESS_ROW ipRow;
@@ -220,7 +225,7 @@ int main()
220225
}
221226

222227
// Assign a new IPv6 address to the loopback adapter
223-
// Note that
228+
// Note that luid is assigned in DumpIPv6Config()
224229
const char* ipv6Address = "2001:db8::1234"; // Example IPv6 address
225230
const char* prefixLength = "64"; // Example prefix length
226231

0 commit comments

Comments
 (0)