mirror of
https://github.com/riba2534/TCP-IP-NetworkNote.git
synced 2026-06-30 18:06:04 +08:00
通过多智能体工作流对 19 章笔记(README.md)与 96 个 .c 示例代码做深度 审查与对抗性验证,修复 317 处确认问题,涵盖: 技术正确性: - 修复缓冲区溢出:echo_mpserv.c / echo_storeserv.c 等的 read(buf, BUFSIZ) 改为 BUF_SIZE(buf 仅 30 字节,BUFSIZ 远大于此) - 修复 open() 缺少 mode 参数:low_open.c / fd_seri.c / desto.c 等 O_CREAT 调用补 0644(原导致 low_read 链路失败) - 修复 feof 循环 off-by-one:news_sender.c / echo_stdserv.c 改用 fgets 返回值判断 - 修复线程竞态:chat_server.c / webserv_linux.c 的 &clnt_sock 栈地址 传子线程改为 malloc 分配 + free - 修复索引混淆:char_EPLTserv.c 错用 clnt_sock 查找改为 ep_events[i].data.fd - 修复格式化符:thread4.c 的 sizeof 用 %d 改为 %zu - 修正习题答案:ch01 fd 序号、ch13 MSG_OOB 加粗项、ch09 Nagle 等 文档规范: - 统一术语:IPv4/IPv6、接收(receive)/连接(connection) - 修正错别字:occured→occurred、cooffee→coffee、Usgae→Usage、 eerror→error、proess→process 等 - 修复病句、补全习题答案解释 - GitHub 绝对 URL 改为相对路径,统一项目引用规范 - 同步根 README.md(前言 + 19 章合并) 另:重命名 ch10/remove_zomebie.c → remove_zombie.c(修正拼写) 所有 .c 文件经 gcc 编译验证通过(ch17 epoll 文件因 macOS 无 sys/epoll.h 跳过,已人工复核)。
40 lines
1.1 KiB
C
40 lines
1.1 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <arpa/inet.h>
|
|
#include <netdb.h>
|
|
void error_handling(char *message);
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int i;
|
|
struct hostent *host;
|
|
if (argc != 2)
|
|
{
|
|
printf("Usage : %s <domain>\n", argv[0]);
|
|
exit(1);
|
|
}
|
|
// 把参数传递给函数,返回结构体
|
|
host = gethostbyname(argv[1]);
|
|
if (!host)
|
|
error_handling("gethost... error");
|
|
// 输出官方域名
|
|
printf("Official name: %s \n", host->h_name);
|
|
// Aliases 为该主机的别名(常对应 DNS 的 CNAME 记录)
|
|
for (i = 0; host->h_aliases[i]; i++)
|
|
printf("Aliases %d: %s \n", i + 1, host->h_aliases[i]);
|
|
//看看是不是ipv4
|
|
printf("Address type: %s \n",
|
|
(host->h_addrtype == AF_INET) ? "AF_INET" : "AF_INET6");
|
|
// 输出ip地址信息
|
|
for (i = 0; host->h_addr_list[i]; i++)
|
|
printf("IP addr %d: %s \n", i + 1,
|
|
inet_ntoa(*(struct in_addr *)host->h_addr_list[i]));
|
|
return 0;
|
|
}
|
|
void error_handling(char *message)
|
|
{
|
|
fputs(message, stderr);
|
|
fputc('\n', stderr);
|
|
exit(1);
|
|
} |