#include #include #include #include using namespace std; const int BUFFER_SIZE{1000}; int main() { int i; string hostname; cout << "Enter the host name :"; cin >> hostname; cout << endl; struct hostent * result{ gethostbyname(hostname.c_str())}; if (result != nullptr) { cout << "The h_name field is " << result->h_name << endl; if (result->h_aliases[0] != nullptr) { cout << "AKA: " << endl; i = 0; while (result->h_aliases[i] != nullptr) { cout << "\t" << result->h_aliases[i] << endl; ++i; } } if (result->h_addrtype == AF_INET) { cout << "\tThis is IPV4" << endl; } else if (result->h_addrtype == AF_INET6) { cout << "\tThis is IPV6" << endl; } else { cout << "\tUnknown address type " << endl; } cout << "\tThe address is " << result->h_length << " bytes." << endl; i = 0; char buffer[BUFFER_SIZE]; while (result->h_addr_list[i] != nullptr) { cout << "\tThere is an address " << inet_ntop(result->h_addrtype, result->h_addr_list[i], buffer, BUFFER_SIZE) << endl; ++i; } } else { herror("gethostbyname: "); } return 0; }