Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <conio.h>
  3. #include <winsock.h>
  4. #pragma comment(lib, "ws2_32.lib")
  5.  
  6. int _tmain(int argc, _TCHAR* argv[])
  7. {
  8.     WSADATA ws;
  9.     int start = WSAStartup(MAKEWORD(1,1), &ws);
  10.     if(start != NO_ERROR)
  11.     {
  12.         printf("Blad startu WinSocka\n");
  13.         _getch();
  14.         return 0;
  15.     }
  16.  
  17.     char hostName [128];
  18.     //gethostname(hostName, sizeof(hostName));
  19.  
  20.     if(hostName != NULL)
  21.     {
  22.         printf("%s\n", hostName);
  23.     }
  24.     else
  25.     {
  26.         printf("Problem ze wczytaniem nazwy hosta\n");
  27.     }
  28.  
  29.     hostent* host = gethostbyname("google.com");
  30.     if(host == 0)
  31.     {
  32.         printf("blad przypisania hosta\n");
  33.     }
  34.     else
  35.     {
  36.         if(host->h_addrtype == AF_INET)
  37.         {
  38.             int i = 0;
  39.             in_addr address;
  40.             while(host->h_addr_list[i])
  41.             {
  42.                 address = *(in_addr*) host->h_addr_list[i++];
  43.                 printf("%s\n", inet_ntoa(address));
  44.             }
  45.         }
  46.         else
  47.         {
  48.             printf("niepoprawny address\n");
  49.         }
  50.     }
  51.     WSACleanup();
  52.     _getch();
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement