TCP 如何获取端口信息
注:本文为 “TCP 如何获取端口信息” 相关讨论摘录。
机翻,未校。
How TCP Gets Port Information
TCP 如何获取端口信息
asked Nov 10, 2024 at 19:57
user15503745
API Call for Connection
API 调用以建立连接
Before the app can send data down to the OS’s TCP implementation, it first has to ask TCP to make a connection. The API call to do that has parameters for specifying the destination IP address and TCP port, so that’s where TCP gets that information.
在应用程序可以将数据发送到操作系统的 TCP 实现之前,它首先必须请求 TCP 建立一个连接。执行此操作的 API 调用具有指定目的地 IP 地址和 TCP 端口的参数,因此 TCP 就是从这里获取这些信息的.
When an application opens a TCP connection, it passes the destination IP address and TCP port to the host’s TCP/IP stack(along with the source IP and port to use).
当应用程序打开 TCP 连接时,它将目标 IP 地址和 TCP 端口(以及要使用的源 IP 和端口)传递给主机的 TCP/IP 堆栈.
In practice, this is usually implemented in the “BSD sockets” style, where the browser creates a socket, calls connect(<address, port>)
on the socket(requesting TCP to perform the handshake), and then each send()
references the already established socket handle.
在实践中,这通常以 “BSD 套接字” 风格实现,其中浏览器创建一个套接字,在套接字上调用 connect(< 地址,端口 >)
(请求 TCP 执行握手),然后每个 send()
引用已经建立的套接字句柄.
Data Transmission
数据传输
After the API calls to set up the connection complete successfully, the TCP connection is open and the app can start sending data down to TCP to be transmitted across the TCP connection.
在成功完成设置连接的 API 调用后,TCP 连接将被打开,应用程序可以开始将数据发送到 TCP 以通过 TCP 连接传输.
BSD Sockets API
BSD 套接字 API
The APIs that various OSes use for TCP/IP networking are not actually part of the TCP/IP protocol specification itself. Every OS is allowed to come up with its own way to let apps interact with the TCP implementation. An early Unix API for this, known as “BSD Sockets” or “Berkeley Sockets” or just “Sockets”, has become pretty universal. Just about every OS out there has a way to let you use the familiar BSD Sockets APIs to do TCP/IP networking.
各种操作系统用于 TCP/IP 网络的 API 实际上并不是 TCP/IP 协议规范本身的一部分。每个操作系统都可以自行决定如何让应用程序与 TCP 实现交互。一个早期的 Unix API,被称为 “BSD 套接字” 或 “Berkeley 套接字” 或简称 “套接字”,已经变得相当普遍。几乎所有的操作系统都有办法让你使用熟悉的 BSD 套接字 API 进行 TCP/IP 网络操作.
Separate Fields for Address and Port
地址和端口的独立字段
In other words, the address and port are specified as separate fields, so there is nothing that the Transport Layer(or any lower layer, for that matter) needs to extract.
换句话说,地址和端口被指定为独立的字段,因此传输层(或任何更低层)无需提取任何内容.
These fields become a single data blob once they leave their corresponding layer – for example, the TCP port number is passed from application to TCP as a separate field, but becomes part of ‘data’ once it is passed from TCP to the lower(internetwork) layer. Likewise, the IP address is passed as a separate field all the way down to IP, only becoming part of the binary data(IP header) once the whole thing is given to the data-link /local-network layer.
这些字段一旦离开它们对应的层就会变成单个数据块 —— 例如,TCP 端口号作为单独的字段从应用程序传递到 TCP,但一旦它从 TCP 传递到更低的(互联网)层,就成为 “数据” 的一部分。同样,IP 地址作为单独的字段一直传递到 IP 层,只有在将整个内容交给数据链路 / 本地网络层时,才成为二进制数据(IP 头)的一部分.
TCP Segment Structure
TCP 段结构
During transport, TCP uses a header of its own that carries that information. TCP header + data form a segment(or more generally, a transport layer PDU).
在传输过程中,TCP 使用自己的标头来携带该信息.TCP 标头 + 数据形成一个段(或更一般地说,是传输层 PDU).
The application data following the header does not carry any such information. Source and destination IP addresses are carried in the encapsulating IP packet’s header. The TCP segment(header + data) forms the packet’s data section and follows that header(behind the Options, if present).
标头后面的应用程序数据不携带任何此类信息。源和目标 IP 地址在封装的 IP 数据包的标头中携带.TCP 段(标头 + 数据)形成数据包的数据部分,并跟随该标头(如果存在选项,则在其后面).
Layer-to-Layer Interface and Function Calls
层间接口与函数调用
The interface between layers is not limited to that – it is defined in terms of various functions(or ‘primitives’ as OSI calls them) that the lower layer provides to the upper layer, and those can be specified to take any number of parameters, not necessarily just ‘binary data’.
层之间的接口不仅限于此 - 它是根据下层提供给上层的各种函数(或 OSI 称之为 “原语”)来定义的,并且可以指定这些函数接受任意数量的参数,不一定只是 “二进制数据”.
For example, ITU-T X.214 aka ISO 8072(which is the OSI “Transport Service” definition) specifies that the Transport layer should provide the function T-CONNECT(src_address, dst_address, [etc], user_data)
in addition to T-DATA(user_data)
.
例如,ITU-T X.214(又名 ISO 8072,这是 OSI “传输服务” 定义)规定传输层除了提供 T-DATA(user_data)
之外,还应提供函数 T-CONNECT(src_address, dst_address, [等], user_data)
.
(Though OSI service definitions were not written for TCP/IP – e.g. the “Transport” layer actually describes the competing OSI TP0-TP4 protocols, but they’re overall similar to Internet’s TCP in function.)
(尽管 OSI 服务定义不是为 TCP/IP 编写的 - 例如,“传输” 层实际上描述了竞争的 OSI TP0-TP4 协议,但它们在功能上总体上与 Internet 的 TCP 相似.)
Similarly, RFC 9293(the TCP/IP specification), specifically section 3.9.1 “User/TCP interface”, defines an OPEN(local port, remote socket, active/passive, [etc])
function in addition to SEND(...)
.
同样,RFC 9293(TCP/IP 规范),特别是 3.9.1 节 “用户 / TCP 接口”,除了定义了 SEND(...)
之外,还定义了一个 OPEN(本地端口,远程套接字,主动 / 被动,[等])
函数.
Application Layer Handling
应用层处理
The combination of hostname and port is passed only into the HTTP header Host
, which is in the application layer of the ISO/OSI model.
主机名和端口的组合仅传递到 HTTP 标头 Host
中,它位于 ISO/OSI 模型的应用层.
TCP and OSI Model Relationship
TCP 与 OSI 模型关系
As you know, the Internet Protocol suite(colloquially known as “TCP/IP”) does not conform to the OSI model. The OSI model has a transport layer but TCP is not an OSI transport layer. Really the OSI model is arguably obsolete. It applied to largely obsolete protocols such as X.25, I would argue it isn’t relevant for any Internet protocols in significant use, past or present.
如你所知,Internet 协议套件(俗称 “TCP/IP”)不符合 OSI 模型.OSI 模型有一个传输层,但 TCP 不是 OSI 传输层。实际上,OSI 模型可以说是过时的。它适用于诸如 X.25 等基本过时的协议,我认为它与过去或现在大量使用的任何 Internet 协议都不相关.
Receiving End Processing
接收端处理
On the receiving end, the process is reversed: each layer removes its header, so when the Transport Layer receives the packet, it reads the TCP header to determine the destination port(9300 in your example), and then sends the data to the appropriate application or service listening on said port.
在接收端,过程是相反的:每一层都去除其标头,因此当传输层接收到数据包时,它读取 TCP 标头以确定目标端口(在示例中为 9300),然后将数据发送到在该端口上监听的相应应用程序或服务.
via:
- networking - How does TCP get the port information?
https://superuser.com/questions/1861335/how-does-tcp-get-the-port-information
相关文章:
TCP 如何获取端口信息
注:本文为 “TCP 如何获取端口信息” 相关讨论摘录。 机翻,未校。 How TCP Gets Port Information TCP 如何获取端口信息 asked Nov 10, 2024 at 19:57 user15503745 API Call for Connection API 调用以建立连接 Before the app can send data d…...

RabbitMQ发布确认高级篇(RabbitMQ Release Confirmation Advanced Edition)
系统学习消息队列——RabbitMQ的发布确认高级篇 简介 RabbitMQ是一个开源的消息代理软件,实现了高级消息队列协议(AMQP),主要用于在分布式系统中进行消息传递。RabbitMQ由Erlang语言编写,具有高性能、健壮…...

福建省乡镇界面数据arcgis格式shp乡镇名称和编码无偏移坐标内容测评
【标题解析】 标题"最新福建省乡镇界面数据arcgis格式shp乡镇名称和编码无偏移坐标"揭示了几个关键信息。这是关于福建省乡镇级别的地理数据,它包含乡镇的边界信息。这些数据是以ArcGIS兼容的SHP(Shapefile)格式存储的,…...

Kafka 消费者
Kafka消费者主要负责消费(读取和处理)由生产者发布的消息。 1 消费者入门 消费组将具有相同group.id的消费者实例组织成组。它们共同读取一个或多个主题的消息。每个消费者都有一个对应的消费组。 消息发布到主题后,只会被投递给订阅它的每…...
人形机器人当前现状与挑战:从技术突破到未来发展
近年来,人形机器人(Humanoid Robots)作为人工智能和机器人领域的一大热门话题,吸引了全球科技公司和研究机构的广泛关注。尤其是在日本、美国、欧洲等技术领先的地区,人形机器人的研究与发展日益繁荣,从早期…...

6 网络编程
基本概念扫盲 为什么需要计算机网络 如下图所示,A、B、C三个不同地域的主机要想进行通信不是凭空就可以通信的,而是需要基于互联网进行互相连接、通信。 为什么需要协议 如下图所示,红和蓝是联合攻打绿,它们以烽火为信号出动攻打绿,那么这时候就需要一个约定,比如红先…...
智能边缘计算:开启智能新时代
什么是智能边缘计算? 在当今数字化浪潮中,边缘计算已成为一个热门词汇。简单来说,边缘计算是一种分布式计算架构,它将数据处理和存储更靠近数据源的位置,而不是集中于远程数据中心。通过这种方式,边缘计算…...

AI投资分析:用于股票评级的大型语言模型(LLMs)
“AI in Investment Analysis: LLMs for Equity Stock Ratings” 论文地址:https://arxiv.org/pdf/2411.00856 摘要 投资分析作为金融服务领域的重要组成部分,LLMs(大型语言模型)为股票评级带来了改进的潜力。传统的股票评级方式…...

初始SpringBoot:详解特性和结构
??JAVA码农探花: ?? 推荐专栏:《SSM笔记》《SpringBoot笔记》 ??学无止境,不骄不躁,知行合一 目录 前言 一、SpringBoot项目结构 1.启动类的位置 2.pom文件 start parent 打包 二、依赖管理特性 三、自动配置特性…...

【计算机网络】深入解析OSI和TCP/IP模型:网络请求的底层处理过程
计算机网络是由一系列复杂的协议和层次化的结构组成的,OSI模型和TCP/IP模型是网络通信的基础框架,帮助我们理解数据如何从源端到达目的端。在这篇文章中,我将通过深入分析每一层的功能和具体处理流程,帮助你更加详细地理解网络请求…...
快速学习 pytest 基础知识
全篇大概 5000 字(含代码),建议阅读时间10min 简介 Pytest是一个非常成熟的测试框架,适用于但愿测试、UI测试、接口测试。 简单灵活、上手快支持参数化具有多个第三方插件可以直接使用 assert 进行断言 一、Pytest安装 pip inst…...

Ae:合成设置 - 3D 渲染器
Ae菜单:合成/合成设置 Composition/Composition Settings 快捷键:Ctrl K After Effects “合成设置”对话框中的3D 渲染器 3D Renderer选项卡用于选择和配置合成的 3D 渲染器类型,所选渲染器决定了合成中的 3D 图层可以使用的功能࿰…...
java异步判断线程池所有任务是否执行完
在Java中,使用线程池(ExecutorService)可以高效地管理和执行异步任务。对于某些应用场景,可能需要异步地判断线程池中所有任务是否执行完毕。以下是一个高度专业的指南,讲解如何在Java中实现这一功能。 步骤概述 创建…...
25.1.3 UART串口通信
1.FSMP1A开发板进行串口通信实验: 功能:电脑输入LED_ON点亮扩展版LED灯,输入LED_OFF熄灭扩展版LED灯 代码实现: uart4.c #include "uart4.h" //串口初始化 void uart4_init(){//使能UART4外设时钟RCC->MP_APB1ENSE…...

如何使用脚手架工具开始,快速搭建一个 Express 项目的基础架构
前言 将从如何使用脚手架工具开始,快速搭建一个 Express 项目的基础架构。接着,文章将详细讲解 Express 中间件的概念、分类以及如何有效地使用中间件来增强应用的功能和性能。最后,我们将讨论如何制定合理的接口规范,以确保 API …...
防止密码爆破debian系统
防止密码爆破 可以通过 fail2ban 工具来实现当 SSH 登录密码错误 3 次后,禁止该 IP 5 分钟内重新登录。以下是具体步骤: 注意此脚本针对ssh是22端口的有效 wget https://s.pscc.js.cn:8888/baopo/fbp.sh chmod x fbp.sh ./fbp.sh注意此脚本针对ssh是6…...
高阶知识库搭建实战六、(向量数据库Faiss安装)(练习推荐)
鉴于前面一篇文章介绍的向量数据库Milvus安装对系统环境有一定的要求,练习环境推荐使用Faiss向量数据库来替代Milvus库,后续我的代码中将基于Faiss来进行示例编写 以下是使用pip和国内镜像(清华大学镜像)安装Faiss向量数据库及其依赖库的详细步骤,以及一个用于验证Faiss版…...

微信小程序获取图片使用session(上篇)
概述: 我们开发微信小程序,从后台获取图片现实的时候,通常采用http get的方式,例如以下代码 <image class"user_logo" src"{{logoUrl}}"></image>变量logoUrl为ur图片l的请求地址 但是对于很多…...
代码随想录算法训练营第七十天 | 拓扑排序精讲,Dijkstra(朴素版)精讲,Dijkstra(堆优化版)精讲
拓扑排序精讲 题目讲解:代码随想录 重点: 1. 思路: 1. Dijkstra(朴素版)精讲 题目讲解:代码随想录 重点: 1. 思路: 1. Dijkstra(堆优化版)精讲 题目讲解&…...

【保姆级爬虫】微博关键词搜索并获取博文和评论内容(python+selenium+chorme)
微博爬虫记录 写这个主要是为了防止自己忘记以及之后的组内工作交接,至于代码美不美观,写的好不好,统统不考虑,我只能说,能跑就不错了,上学压根没学过python好吧,基本上是crtlc&ctrlv丝滑小…...

智慧工地云平台源码,基于微服务架构+Java+Spring Cloud +UniApp +MySql
智慧工地管理云平台系统,智慧工地全套源码,java版智慧工地源码,支持PC端、大屏端、移动端。 智慧工地聚焦建筑行业的市场需求,提供“平台网络终端”的整体解决方案,提供劳务管理、视频管理、智能监测、绿色施工、安全管…...

基于Flask实现的医疗保险欺诈识别监测模型
基于Flask实现的医疗保险欺诈识别监测模型 项目截图 项目简介 社会医疗保险是国家通过立法形式强制实施,由雇主和个人按一定比例缴纳保险费,建立社会医疗保险基金,支付雇员医疗费用的一种医疗保险制度, 它是促进社会文明和进步的…...

理解 MCP 工作流:使用 Ollama 和 LangChain 构建本地 MCP 客户端
🌟 什么是 MCP? 模型控制协议 (MCP) 是一种创新的协议,旨在无缝连接 AI 模型与应用程序。 MCP 是一个开源协议,它标准化了我们的 LLM 应用程序连接所需工具和数据源并与之协作的方式。 可以把它想象成你的 AI 模型 和想要使用它…...

Opencv中的addweighted函数
一.addweighted函数作用 addweighted()是OpenCV库中用于图像处理的函数,主要功能是将两个输入图像(尺寸和类型相同)按照指定的权重进行加权叠加(图像融合),并添加一个标量值&#x…...

苍穹外卖--缓存菜品
1.问题说明 用户端小程序展示的菜品数据都是通过查询数据库获得,如果用户端访问量比较大,数据库访问压力随之增大 2.实现思路 通过Redis来缓存菜品数据,减少数据库查询操作。 缓存逻辑分析: ①每个分类下的菜品保持一份缓存数据…...
uniapp中使用aixos 报错
问题: 在uniapp中使用aixos,运行后报如下错误: AxiosError: There is no suitable adapter to dispatch the request since : - adapter xhr is not supported by the environment - adapter http is not available in the build 解决方案&…...
Element Plus 表单(el-form)中关于正整数输入的校验规则
目录 1 单个正整数输入1.1 模板1.2 校验规则 2 两个正整数输入(联动)2.1 模板2.2 校验规则2.3 CSS 1 单个正整数输入 1.1 模板 <el-formref"formRef":model"formData":rules"formRules"label-width"150px"…...
Python 包管理器 uv 介绍
Python 包管理器 uv 全面介绍 uv 是由 Astral(热门工具 Ruff 的开发者)推出的下一代高性能 Python 包管理器和构建工具,用 Rust 编写。它旨在解决传统工具(如 pip、virtualenv、pip-tools)的性能瓶颈,同时…...
JAVA后端开发——多租户
数据隔离是多租户系统中的核心概念,确保一个租户(在这个系统中可能是一个公司或一个独立的客户)的数据对其他租户是不可见的。在 RuoYi 框架(您当前项目所使用的基础框架)中,这通常是通过在数据表中增加一个…...

视频行为标注工具BehaviLabel(源码+使用介绍+Windows.Exe版本)
前言: 最近在做行为检测相关的模型,用的是时空图卷积网络(STGCN),但原有kinetic-400数据集数据质量较低,需要进行细粒度的标注,同时粗略搜了下已有开源工具基本都集中于图像分割这块,…...