依睛(IT blog) 我回来了,PHP<-->C/C++ LINUX

笨鸟

导航

<2007年6月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

留言簿(26)

随笔分类(315)

文章分类(5)

收藏夹

随笔档案(330)

文章档案(11)

相册

阅读排行榜

评论排行榜

统计

积分与排名

友情连接

最新评论

Linux下c实现 IP转为域名

原创 Linux下c实现 IP转为域名收藏

都是入门级的例子
练手而已

/***************************************************************************
 *   Copyright (C) 2008 by root   *
Linux下c实现   IP转为域名
 ***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>

int main(int argc, char *argv[])
{
    struct sockaddr_in addr;
    struct hostent *host;
    char ipaddr[40];
    printf("请输入IP\n");
    scanf("%s",ipaddr);
    getchar();
    if(inet_aton(ipaddr,&addr.sin_addr)!=0)
    {
        host=gethostbyaddr((char *)&addr.sin_addr,4,AF_INET);
       
    }
    if(host==NULL)
    {
        fprintf(stderr,"NO address information of host %s\n",ipaddr);
        exit(1);
    }
   
    printf("HostName :%s\n",host->h_name);
    printf("主机别名: %s\n",host->h_aliases);
    printf("IP Address :%s\n",ipaddr);
    return 0;
   
}

posted on 2008-12-14 13:14 向左向右走 阅读(899) 评论(0)  编辑 收藏 引用 所属分类: C/C++学习资料库Linux 学习库

只有注册用户登录后才能发表评论。