文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>继linux Socket1

继linux Socket1

时间:2006-03-31  来源:TurboDisk

下面是nslookup的C版本,当然在C里要稍麻烦一些,到学习完这个小程序为止我还没有得到C版本中的一些数据结构,比如hostent等,不知道去哪里查看这些东西,希望在CU的帖中能会得知罢。
#include <stdio.h> /* stderr, stdout */
#include <netdb.h> /* hostent struct, gethostbyname() */
#include <arpa/inet.h> /* inet_ntoa() to format IP address */
#include <netinet/in.h> /* in_addr structure */
int main(int argc, char **argv) {
struct hostent *host; /* host information */
struct in_addr h_addr; /* Internet address */
if (argc != 2) {
fprintf(stderr, "USAGE: nslookup <inet_address>\n");
exit(1);
}
if ((host = gethostbyname(argv[1])) == NULL) {
fprintf(stderr, "(mini) nslookup failed on '%s'\n", argv[1]);
exit(1);
}
h_addr.s_addr = *((unsigned long *) host->h_addr_list[0]);
fprintf(stdout, "%s\n", inet_ntoa(h_addr));
exit(0);
}
相关阅读 更多 +
排行榜 更多 +
昆虫粉碎者

昆虫粉碎者

休闲益智 下载
瀑布战棋

瀑布战棋

休闲益智 下载
让炸弹飞

让炸弹飞

飞行射击 下载