Advertisement
seberm

site C

Jul 2nd, 2011
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1.  
  2. #include <netdb.h>
  3. #include <netinet/in.h>
  4. #include <arpa/inet.h>
  5.  
  6. #include <iostream>
  7. using namespace std;
  8.  
  9. int main() {
  10.  
  11.     const char name[] = "seberm.com";
  12.  
  13.     /*
  14.      *        char   *h_name       Official name of the host.
  15.               char  **h_aliases    A pointer to an array of pointers to
  16.                                    alternative host names, terminated by a
  17.                                    null pointer.
  18.               int     h_addrtype   Address type.
  19.               int     h_length     The length, in bytes, of the address.
  20.               char  **h_addr_list  A pointer to an array of pointers to network
  21.                                    addresses (in network byte order) for the host,
  22.                                    terminated by a null pointer.
  23.      */
  24.  
  25.     hostent *h = gethostbyname(name);
  26.     cout << "\nname: " << h->h_name << "\n";
  27.  
  28.     int key = 0;
  29.     while (h->h_addr_list[key] != NULL) {
  30.  
  31.         // adresu jsme ziskali v binarni podobne a musime ji prevest fci inet_ntoa na klasickou podobu
  32.         cout << "\nAdresa: " << inet_ntoa(*(in_addr*)h->h_addr_list[key]);
  33.  
  34.         key++;
  35.     }
  36.  
  37.     cout << "\n\n";
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement