默认的本地主机域名localhost总是映射为回送地址(loopback address )127.0.0.1linux> nslookup localhost Address:127.0.0.1
命令行下输入:hostname会得到本机的IP地址。
在通常情况下,多个域名可以映射到同一个或同一组IP地址;

1.5 地址转换的示例

编写的函数hex2dd.c会将它的十六进制参数转换为点分十进制串:#include#include#include "csapp.h" int main(int argc, char **argv) { struct in_addr inaddr; uint32_t addr; char buf[MAXBUF]; if(argc != 2){ fprintf(stderr, "usage:%s
\n",argv[0]); exit(0); } sscanf(argv[1],"%x",&addr); inaddr.s_addr = htonl(addr); if(!inet_ntop(AF_INET,&inaddr,buf,MAXBUF)) unix_error("inet_ntop"); printf("%s\n",buf); exit(0); }
编写的函数dd2hex.c会将它的点分十进制串参数转换为十六进制:
#include#include#include "csapp.h" int main(int argc, char **argv) { struct in_addr inaddr; int rc; if(argc != 2){ fprintf(stderr, "usage:%s\n",argv[0]); exit(0); } rc = inet_pton(AF_INET, argv[1], &inaddr); if(rc == 0) app_error("inet_pton error:invalid dotted-decimal address.\n"); elseif(rc