⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test12_2.txt

📁 linux under the C programming which complementary with the book of <linux under the C programming
💻 TXT
字号:
#include "headfile.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <netdb.h>

int main(int argc,char **argv)
{
  	char ptr,*pptr;
    	char str[INET6_ADDRSTRLEN];
    	struct hostent *hptr;
	while(--argc>0)
	{
    		ptr=*(++argv);
    		if(hptr=gethostbyname(ptr)==NULL)
    		{
      			err_msg("gethostbyname call error:%s,%s\n",ptr,hstrerror(h_error));
      			continue;
    		}
    		printf("canonical name:%s\n",hptr->h_name);
    		for(pptr=hptr->h_aliases;*pptr!=NULL;pptr++)
      			printf("the aliases name is:%s\n",*pptr);
    		switch(hptr->h_addrtype)
    		{
      			case  AF_INET:
      			case  AF_INET6:
      				pptr=hptr->h_addr_list;
      				for(;*pptr!=NULL;pptr++)
        				printf("address:%s\n",inet_ntop(hptr->h_addrtype,*pptr,str,sizeof(str)));
      				break;
      			default:
        			err_sys("unknown addrtype");
      				break;
    		}
	}
	exit(0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -