Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <conio.h>
- #include <winsock.h>
- #pragma comment(lib, "ws2_32.lib")
- int _tmain(int argc, _TCHAR* argv[])
- {
- WSADATA ws;
- int start = WSAStartup(MAKEWORD(1,1), &ws);
- if(start != NO_ERROR)
- {
- printf("Blad startu WinSocka\n");
- _getch();
- return 0;
- }
- char hostName [128];
- //gethostname(hostName, sizeof(hostName));
- if(hostName != NULL)
- {
- printf("%s\n", hostName);
- }
- else
- {
- printf("Problem ze wczytaniem nazwy hosta\n");
- }
- hostent* host = gethostbyname("google.com");
- if(host == 0)
- {
- printf("blad przypisania hosta\n");
- }
- else
- {
- if(host->h_addrtype == AF_INET)
- {
- int i = 0;
- in_addr address;
- while(host->h_addr_list[i])
- {
- address = *(in_addr*) host->h_addr_list[i++];
- printf("%s\n", inet_ntoa(address));
- }
- }
- else
- {
- printf("niepoprawny address\n");
- }
- }
- WSACleanup();
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement