char lHostName[ 255 ];

PHOSTENT lHostInfo;

char *IpBuffer;

WSADATA wsaData;


if( WSAStartup( MAKEWORD( 2,0 ), &wsaData ) == 0 )

{

if( gethostname( lHostName, 255 ) == 0 )

{

if( ( lHostInfo = gethostbyname( lHostName ) ) != NULL )

{

IpBuffer = inet_ntoa( *( struct in_addr * )*lHostInfo->h_addr_list );

}

}

}


CString LocalAdap;
 CString LocalMac;
 CString LocalIP;
 CString LocalSub;
 CString LocalGate;

 PIP_ADAPTER_INFO pAdapterInfo;
 PIP_ADAPTER_INFO pAdapter = NULL;

 DWORD dwRetVal = 0;
 BOOL m_bBreak = FALSE;

 pAdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
 unsigned long ulOutBufLen = sizeof(IP_ADAPTER_INFO);

 UpdateData(true);

 if(GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) != ERROR_SUCCESS)
 {
  GlobalFree(pAdapterInfo);
  pAdapterInfo = (IP_ADAPTER_INFO*)malloc(ulOutBufLen);
 }

 if((dwRetVal=GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR)
 {
  pAdapter = pAdapterInfo;
  while(pAdapter)
  {
   LocalAdap.Format (_T("%s"), (CA2W)pAdapter->Description);
   m_listbox.AddString(LocalAdap);

   LocalMac.Format (_T("MAC : %02X-%02X-%02X-%02X-%02X-%02X"),pAdapter->Address[0],pAdapter->Address[1], 
    pAdapter->Address[2], pAdapter->Address[3], pAdapter->Address[4], pAdapter->Address[5]);
   m_listbox.AddString((_T("MAC :"), LocalMac));

   LocalIP.Format (_T("IP : %s"), (CA2W)pAdapter->IpAddressList.IpAddress.String);
   m_listbox.AddString(LocalIP);

   LocalSub.Format (_T("Local : %s"), (CA2W)pAdapter->IpAddressList.IpMask.String);
   m_listbox.AddString(LocalSub);

   if(pAdapter->Next == NULL)
   {
    m_bBreak = TRUE;
    break;
   }
   pAdapter = pAdapter->Next;
  }
 }

'NativeCode > api' 카테고리의 다른 글

Client Source  (0) 2010.03.19
Server Source  (0) 2010.03.19
Winsock 상대방 아이피, 포트 알아내기  (0) 2010.03.19
IPHLPAPI(IP Helper API) functions  (0) 2010.03.19
CSocket 과 CAsyncSocket에서 Thread문제  (0) 2010.03.19

+ Recent posts