| Код | #include "stdafx.h" #include "winsock2.h" #include "iostream.h"
#pragma comment(lib,"wsock32.lib")
void main() { WSADATA wsaData; if (!WSAStartup(WINSOCK_VERSION, &wsaData)) { char chInfo[64]; if (!gethostname(chInfo,sizeof(chInfo))) { cout << chInfo << endl; hostent *sh; sh=gethostbyname((char*)&chInfo); if (sh!=NULL) { cout << sh->h_name << endl; int nAdapter = 0; while ( sh->h_addr_list[nAdapter] ) { struct sockaddr_in adr; memcpy(&adr.sin_addr,sh->h_addr_list[nAdapter],sh->h_length); cout << inet_ntoa(adr.sin_addr) << endl; nAdapter++; } } } else cout << "Error local host " << endl; } else cout << "Winsock initial Bad !!!!" << endl; WSACleanup(); }
| |