我有这个:
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <Iphlpapi.h>
#include <Assert.h>
#include <sstream>
#pragma comment(lib, "iphlpapi.lib")
using namespace std;
// Prints the MAC address stored in a 6 byte array to stdout
static void PrintMACaddress(unsigned char MACData[])
{
printf("%02X-%02X-%02X-%02X-%02X-%02X",
MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]);
}
// Fetches the MAC address and prints it
static void GetMACaddress(void)
{
IP_ADAPTER_INFO AdapterInfo[16]; // Allocate information for up to 16 NICs
DWORD dwBufLen = sizeof(AdapterInfo); // Save the memory size of buffer
DWORD dwStatus = GetAdaptersInfo( // Call GetAdapterInfo
AdapterInfo, // [out] buffer to receive data
&dwBufLen); // [in] size of receive data buffer
assert(dwStatus == ERROR_SUCCESS); // Verify return value is valid, no buffer overflow
PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;// Contains pointer to current adapter info
do {
PrintMACaddress(pAdapterInfo->Address); // Print MAC address
pAdapterInfo = pAdapterInfo->Next; // Progress through linked list
}
while(pAdapterInfo); // Terminate if last adapter
}
int _tmain(int argc, _TCHAR* argv[])
{
char mac[100];
GetMACaddress(); // output is 00-19-D7-53-2D-14
std::stringstream buffer;
buffer << "Text" << std::endl;
cout << buffer.str();
return 0;
}
我的问题是如何将函数GetMACaddress();
输出分配给变量。这:mac = GetMACaddress(); // output is 00-19-D7-53-2D-14
不工作。请帮帮我。谢谢你。
返回 MAC 地址的数据类型为unsigned char
。