002
27.09.2002, 22:12 Uhr
Uwe
C/C++ Master (Administrator)
|
Hallo Flo, nur als Denkanstoß:
C++: |
void CGetIPDlg::OnButton1() { short number = GetNumberOfHostIpAddresses(); /* 2 : in meinem Fall Ethernet - Adapter 1 : DFÜ-Adapter /Modem/ISDN etc.*/ CString strIP = GetHostIPAddressString(1);
}
/* WSADATA wsd; WSAStartup(0x0101,&wsd); erfolgt an geeigneter Stelle */
short CGetIPDlg::GetNumberOfHostIpAddresses() { char szHostname[200]; HOSTENT *pHostEnt; short nLoop = 0; memset(szHostname, 0, 200); if(gethostname(szHostname, sizeof(szHostname))==SOCKET_ERROR) return -1; if(0 == (pHostEnt = gethostbyname(szHostname))) return -1; nLoop = 0; while(pHostEnt->h_addr_list[nLoop] != 0) nLoop++; TRACE(_T("CGetIPDlg::GetNumberOfHostIpAddresses(...) Called. IPs = %d\n"), nLoop); return nLoop; }
CString CGetIPDlg::GetHostIPAddressString(short sAdapter) { TRACE(_T("CGetIPDlg::GetHostIPAddressString(...) called. Adapter = %d\n"), sAdapter); CString strResult; char szHostname[200]; char szIPAddr[16]; LPSTR lpszIPAddr; HOSTENT *pHostEnt; short nAdapter = sAdapter-1; struct sockaddr_in sAddr; memset(szHostname,0,200); memset(&sAddr, 0, sizeof(struct sockaddr_in)); if(nAdapter < 0){ strResult.Empty(); return strResult; } if(gethostname(szHostname, sizeof(szHostname))==SOCKET_ERROR){ strResult.Empty(); return strResult; } if(0 == (pHostEnt = gethostbyname(szHostname))){ strResult.Empty(); return strResult; } if(pHostEnt->h_addr_list[nAdapter]) memcpy(&sAddr.sin_addr.s_addr, pHostEnt->h_addr_list[nAdapter],pHostEnt->h_length); else{ strResult.Empty(); return strResult; } lpszIPAddr = inet_ntoa(sAddr.sin_addr); if(lpszIPAddr){ strcpy((LPSTR)szIPAddr, (LPSTR)lpszIPAddr); strResult = szIPAddr; TRACE(_T("CGetIPDlg::GetHostIPAddressString(...) called. IP = %s.\n"), strResult); return strResult; } else{ strResult.Empty(); TRACE(_T("CGetIPDlg::GetHostIPAddressString(...) called. IP = %s.\n"), strResult); return strResult; } }
|
-- "Es ist schwierig, ein Programm wirklich idiotensicher zu machen, weil Idioten so genial sind."
Bis dann... Uwe Dieser Post wurde am 27.09.2002 um 22:18 Uhr von Uwe editiert. |