prg7_1.c
来自「Unix下用C语言进行网络编程的范例」· C语言 代码 · 共 36 行
C
36 行
// File: prg7_1.c
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
main(int argc, const char **argv)
{
ulong_t addr;
struct hostent *hp;
char **p;
if (argc != 2) {
(void) printf("usage: %s host_name\n", argv[0]);
exit (1);
}
hp = gethostbyname(argv[1]);
if (hp == NULL) {
(void) printf("host information for %s not found\n", argv[1]);
exit (2);
}
for (p = hp->h_addr_list; *p != 0; p++) {
struct in_addr in;
char **q;
(void) memcpy(&in.s_addr, *p, sizeof (in.s_addr));
(void) printf("%s\t%s", inet_ntoa(in), hp->h_name);
for (q = hp->h_aliases; *q != 0; q++)
(void) printf(" %s", *q);
(void) putchar('\n');
}
exit (0);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?