在linux2.6内核中为什么找不到地址转换函数inet_pton的实现?在很多FreeBSD的内核中却能够找到?

pengfoo pengfoo 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在linux2.6内核中为什么找不到inet_pton的实现?在很多FreeBSD的内核中却能够找到?
真的很疑惑,不知道这个inet_pton到底是在linux2.6内核的什么地方呢?不可能找不到的呀?FreeBSD的很多内核里却能找到。实现如下:

#if defined(LIBC_SCCS) && !defined(lint)
19 static const char rcsid[] = "$Id: inet_pton.c,v 1.3.18.2 2005/07/28 07:38:07 marka Exp $";
20 #endif /* LIBC_SCCS and not lint */
21 #include <sys/cdefs.h>
22 __FBSDID("$FreeBSD: head/sys/libkern/inet_pton.c 213103 2010-09-24 15:01:45Z attilio $");
23
24 #include <sys/param.h>
25 #include <sys/socket.h>
26 #include <sys/systm.h>
27
28 #include <netinet/in.h>
29
30 #if __FreeBSD_version < 700000
31 #define strchr index
32 #endif
33
34 /*%
35 * WARNING: Don't even consider trying to compile this on a system where
36 * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
37 */
38
39 static int inet_pton4(const char *src, u_char *dst);
40 static int inet_pton6(const char *src, u_char *dst);
41
42 /* int
43 * inet_pton(af, src, dst)
44 * convert from presentation format (which usually means ASCII printable)
45 * to network format (which is usually some kind of binary format).
46 * return:
47 * 1 if the address was valid for the specified address family
48 * 0 if the address wasn't valid (`dst' is untouched in this case)
49 * -1 if some other error occurred (`dst' is untouched in this case, too)
50 * author:
51 * Paul Vixie, 1996.
52 */
53 int
54 inet_pton(int af, const char *src, void *dst)
55 {
56 switch (af) {
57 case AF_INET:
58 return (inet_pton4(src, dst));
59 case AF_INET6:
60 return (inet_pton6(src, dst));
61 default:
62 return (-1);
63 }
64 /* NOTREACHED */
65 }
66
67 /* int
68 * inet_pton4(src, dst)
69 * like inet_aton() but without all the hexadecimal and shorthand.
70 * return:
71 * 1 if `src' is a valid dotted quad, else 0.
72 * notice:
73 * does not touch `dst' unless it's returning 1.
74 * author:
75 * Paul Vixie, 1996.
76 */
77 static int
78 inet_pton4(const char *src, u_char *dst)
79 {
80 static const char digits[] = "0123456789";
81 int saw_digit, octets, ch;
82 #define NS_INADDRSZ 4
83 u_char tmp[NS_INADDRSZ], *tp;
84
85 saw_digit = 0;
86 octets = 0;
87 *(tp = tmp) = 0;
88 while ((ch = *src++) != '\0') {
89 const char *pch;
90
91 if ((pch = strchr(digits, ch)) != NULL) {
92 u_int new = *tp * 10 + (pch - digits);
93
94 if (saw_digit && *tp == 0)
95 return (0);
96 if (new > 255)
97 return (0);
98 *tp = new;
99 if (!saw_digit) {
100 if (++octets > 4)
101 return (0);
102 saw_digit = 1;
103 }
104 } else if (ch == '.' && saw_digit) {
105 if (octets == 4)
106 return (0);
107 *++tp = 0;
108 saw_digit = 0;
109 } else
110 return (0);
111 }
112 if (octets < 4)
113 return (0);
114 memcpy(dst, tmp, NS_INADDRSZ);
115 return (1);
116 }


我现在钻牛角尖的一个问题是,为什么在linux2.6内核中找不到呢?(我尝试了好几种方法找,1 把linux2.6内核源码下载下来找 2. 在http://fxr.watson.org/fxr/source/libkern/inet_pton.c#L54也找不到)
...全文

相关推荐

简单的Socket select模式源代码(server,client)

简单的Socket select模式源代码(server,client) 能正常运行,基本呈现了socket select模型

huazaimh

高校技术转移办公室人员如何利用平台提升技术成果的市场转化率?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN

人工智能基于Spring AI的流程编排技术:Java开发者实现RAG、工具调用与多Agent协作的系统化方法论

「AI大模型」Spring-AI-流程编排主流做法-保姆级教程 内容概要:本文是一份关于 Spring AI 1.0 GA 版本中流程编排的系统性教程,重点讲解如何利用 Spring AI 的核心机制实现 AI 应用中的标准化、可复用的流程控制。文章从环境搭建入手,深入介绍 ChatClient 作为编排入口的使用方式,并详细阐述 Advisors 拦截链在实现安全过滤、记忆管理、检索增强生成(RAG)、工具调用等功能中的核心作用。进一步覆盖结构化输出、跨进程通信协议 MCP 及基于状态图的复杂工作流引擎 Spring AI Alibaba Graph 等高级编排能力,最后通过一个集成 RAG、工具调用与对话记忆的生产级 Agent 实战案例,展示了全流程自动化的能力。整套体系借鉴了 Servlet Filter 和 LangGraph 思想,强调“约定优于配置”的工程化设计。; 适合人群:具备 Spring Boot 基础,希望系统掌握 AI 应用流程编排的 Java 开发者,尤其是从事企业级 AI 功能开发、Agent 构建及相关平台建设的技术人员。; 使用场景及目标:① 构建具备记忆、RAG、工具调用等复合能力的智能助手;② 实现可插拔、高复用、易测试的 AI 流程组件;③ 设计支持循环、分支和并行的复杂 Agent 工作流;④ 推动跨服务、跨语言的 AI 工具标准化集成(通过 MCP)。; 阅读建议:此资源以 Spring 官方及 Alibaba 生态权威资料为基础,内容紧跟 1.0 GA 最新演进,建议结合官方文档同步实践代码,特别注意版本迁移要点(如 artifactId 更名、Advisor 替换等),并在实际项目中遵循最佳实践规避常见陷阱。

资源创作小能手

产业园区如何精准识别并引进符合本地产业特色的优质科技成果转化项目?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN

阿里云云原生架构白皮书文档

阿里云云原生架构白皮书,由阿里云内部技术团队合著,对整个阿里云云原生产品和架构理念进行了全面深入介绍

元界MetaLite
评论 5
收藏 已收藏
分享
返回顶部
pengfoo
Linux/Unix社区 23,224 成员 74,535 内容