程序博客网 > sql语句跨数据库查询
来源:互联网 发布:sql语句跨数据库查询 编辑:程序博客网 时间:2024/06/06 15:35
#include <unistd.h>#include <errno.h>#include <cstdlib>#include <cstdio>#include <netdb.h> #include <sys/socket.h> #include <arpa/inet.h>int main(int argc, char *argv[]) { // 将要解析的域名或主机名 char *strHostname = "www.ppsdn.net"; if (argc > 1) { strHostname = argv[1]; } struct hostent *sHostent; if (NULL == (sHostent = gethostbyname(strHostname))) { cout << "Error: h_error=" << h_error << endl; perror("Error: gethostbyname()函数调用失败. /n"); return 1; } // 输出"主机的规范名" cout << "official hostname: " << sHostent->h_name << endl; // 输出"主机可能存在的多个别名" char **ppAlias; for (ppAlias = sHostent->h_aliases ; NULL != *ppAlias; ppAlias++) { printf("alias: %s /n", *ppAlias); } // 输出"地址" char str[32]; char **ppAddrList; switch (sHostent->h_addrtype) { case AF_INET: case AF_INET6: ppAddrList = sHostent->h_addr_list; // 将刚才得到的所有地址都打出来。其中调用了inet_ntop()函数 for(; *ppAddrList!=NULL; ppAddrList++) printf("address: %s/n" , inet_ntop(sHostent->h_addrtype, *ppAddrList, str, sizeof(str))); break; default: printf("Error: Unknown address type. /n"); break; } return 0; }