From: Alex Vinokur <ale...@users.sourceforge.net>
Date: Sat, 22 Apr 2006 10:04:10 +0300
Local: Sat, Apr 22 2006 3:04 am
Subject: Usage of gethostbyname()
// ========================== Alex Vinokur
[
// -------------------- // -------------------- // -------------------- // ==================== // ==================== // ==================== return string (host_name); } // ==================== vector<vector<string> > get_hostbyname(const string& host_name_i = string()) { const hostent * const p_host = gethostbyname (host_name_i.c_str()); if (p_host == 0) { CERR << "" << "Unable to perform gethostbyname(" << host_name_i << "): " << "h_errno = " << h_errno << " - " << hstrerror(h_errno) ; return vector<vector<string> > (); } vector<vector<string> > ret_vvect (SIZE_OF_HOSTBYNAME_INFO); ret_vvect[H_NAME].push_back (p_host->h_name); for (int i = 0; p_host->h_aliases[i]; i++) return ret_vvect; } // ==================== void show_hostbyname(const string& host_name_i = string()) { cout << endl; cout << endl; cout << "====== " << "gethostbyname(" << host_name_i << ")" << " ======" << endl; const vector<vector<string> > result = get_hostbyname (host_name_i); for (size_t i = 0; i < result.size(); i++) } // ==================== int main () { const string host_name = get_hostname(); if (!host_name.empty()) { cout << "gethostname() returns host_name = " << host_name << endl; } else { cout << "gethostname() can't return host_name" << endl; } // -------------------- show_hostbyname ("localhost"); if (!host_name.empty()) return 0; }
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||