互联网协议 Internet Protocol Suite

本文介绍了互联网协议的五层模型,包括物理层、链接层、网络层、传输层和应用层,详细阐述了各层的功能,如TCP的三次握手和四次挥手过程,以及IP、MAC地址、端口等概念。通过实例解析,帮助理解网络通信的基本原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

互联网分层模型有7层或4层,但5层更容易解释。
  应用层(Application Layer) 越靠近用户
   ↓
  传输层(Transport Layer)   ↓    不同应用 port
   ↓
  网络层(Network Layer)    ↓    不同网络 IP
   ↓
  链接层(Link Layer)      ↓    同一网络 ARP广播 MAC
   ↓
  物理层(Physical Layer)  越靠近硬件  0/1

物理层

  通过光缆、电缆等实体物理方式连接,传输0/1信号。

链接层

  规定一组电信号构成一个数据包,称为“帧”Frame,分为标头head和数据data,标头包含发送者、接收者、数据类型等,固定18个字节,数据包含具体内容,最短46字节最长1500字节,称为以太网协议。
——————————
| Head |  data  |
——————————
  发送者和接收者指的是网卡的发送地址和接收地址,MAC地址,每卡唯一的12个字节。
  定义了MAC地址,后续需要实现机器之间通信,即ARP地址解析协议Address Resolution Protocol,采用广播的方式,通知本网络内的每台机器,解析标头是否一致,一致则接收,不一致则丢弃。

网络层

  链路层人手一包的通信方式低效且不安全,需要实现不同子网络之间的通信,诞生了网络层,同一子网络采用广播方式发送,不同子网络采用路由方式发送,于是产生网络地址IP,网址。
  MAC地址解决子网络网卡之间通信,IP地址定位每个子网络。
  IP分4段,总共4*8=32bits,依据子网掩码分为网络号和主机号。IP数据包包含在MAC数据包中,IP数据包最长65535字节,所以在以太网数据包中需要分割后发送。网络层确实是否在同一个网络,主机号确定哪台机器。若同一网络则走ARP协议,不同网络则走网关。
—————————————————
| MAC Head | IP Head |  data  |
—————————————————

场景数据包地址
同一个子网络对方的MAC地址,对方的IP地址
非同一个子网络网关的MAC地址,对方的IP地址
传输层

  建立任意两台主机上不同应用之间的通信,端口port,从0到65535。由此产生UDP和TCP协议,最长65535字节,整个数据包包含在网络层数据包中。
———————————————————————
| MAC Head | IP Head | TCP Head |  data  |
———————————————————————

应用层

传输层实现了不同程序之间的通信,应用层实现的是应用内的数据的协议,如图片、文字等。

reference:
互联网协议入门(一):http://www.ruanyifeng.com/blog/2012/05/internet_protocol_suite_part_i.html
互联网协议入门(二):http://www.ruanyifeng.com/blog/2012/06/internet_protocol_suite_part_ii.html
交换机、路由器、网关:https://www.jianshu.com/p/bc1f5ef918ea



IP是什么? IP是互联网协议,IP地址是每个终端的地址。
子网掩码是什么?配合IP地址,说明哪部分是网络号,哪部分是主机号。
网关是什么?一个网络连接到另一个网络的“关口”。
默认网关是什么?对IP数据包中的目的地址找不到存在的其他路由时,路由器所选择的路由。
端口是什么?来自传输层的数据通过不同的端口到达不同的上层应用。
物理地址是什么?是每台PC指定的唯一地址。
DNS是什么?是域名解析器,将指定的域名通过查询数据库翻译成指定的IP地址。



工作模式中的TCP服务器、TCP客户端、UDP(广播)模式?
TCP是有应答的协议,数据稳定可靠,但传输速度不快;
UDP是无应答的协议,数据不稳定不可靠,但传输速度快。

IPv4总共32位,以小数点隔开,总共4段,每段以十进制表示;
=网络号+主机号,子网掩码的二进制为1,对应于网络号,二进制为0,对应于主机号。如下例中169.254.0.0为网络号,0.0.233.180为主机号。

IPv6总共128位,以冒号隔开,总共8段,每段以十六进制表示;
=网络号+主机号,子网掩码的二进制为1,对应于网络号,二进制为0,对应于主机号。如下例中169.254.0.0为网络号,0.0.233.180为主机号。

例子:
IPv4:169.254.233.180
译码:10101001.11111110.11101001.10110100
子网码:255.255.0.0
译码:11111111.11111111.00000000.00000000
IPv6:fe80::58b6:e12:1a8c:e9b4 //::表示中间省略的0段,且只能省略一次
完整:fe80:0000:0000:0000:58b6:0e12:1a8c:e9b4
译码:1111111010000000.0000000000000000.0000000000000000.0000000000000000.
101100010110110.0000111000010010.0001101010001100.1110100110110100
可以发现IPv4的主机号与IPv6的后段。


层号中文名英文名缩写
7应用层Application LayerA
6表示层Presentation LayerP
5会话层Session LayerS
4传输层Transport LayerT
3网络层Network LayerN
2数据链路层Data Link LaterDL
1物理层Physical LayerPH

具体功能:
第1层物理层(Physical Layer)
  在局部局域网络上传送帧,它负责管理电脑通信设备和网络媒体之间的互通。包括了针脚、电压、线缆规范、集线器、中继器、网卡、主机适配器等。如RS232,强调的是底层硬件。
第2层数据链路层(Data Link Layer)
  负责网络寻址、错误侦测和改错。当表头和表尾被加至数据包时,会形成了帧。数据链表头(DLH)是包含了物理地址和错误侦测及改错的方法。数据链表尾(DLT)是一串指示数据包末端的字符串。例如以太网、无线局域网(Wi-Fi)和通用分组无线服务(GPRS)等。
第3层网络层(Network Layer)
  决定数据的路径选择和转寄,它网络表头(NH)加至数据报,以形成分组。网络表头包含了网络数据。例如:互联网协议(IP)等,强调的是网络走向。
第4层传输层(Transport Layer)
  把传输表头(TH)加至数据以形成数据报。传输表头包含了所使用的协议等发送信息。例如:传输控制协议义(TCP) 、UDP等,强调的是可靠额数据报,并给出传送给下一层不同应用的不同端口。
第5层会话层(Session Layer)
  负责在数据传输中设置和维护电脑网络中两台电脑之间的通信连接。
第6层表示层(Presentation Layer)
  把数据转换为能与接收者的系统格式兼容并适合传输的格式。
第7层应用层(Application Layer)
  提供为应用软件而设的界面,以设置与另一应用软件之间的通信。例如: HTTP,HTTPS,FTP,TELNET,SSH,SMTP,POP3等。


三次握手,四次挥手

这里写图片描述

TCP建立连接图

这里写图片描述
符号说明
seq:”sequance”序列号
ack:”acknowledge”确认号
SYN:”synchronize”请求同步标志
ACK:”acknowledge”确认标志”
FIN:”Finally”结束标志

为什么收到Server端的确认之后,Client还需要进行第三次“握手”呢?
  在只有两次“握手”的情形下,假设Client想跟Server建立连接,但是却因为中途连接请求的数据报丢失了,故Client端不得不重新发送一遍;这个时候Server端仅收到一个连接请求,因此可以正常的建立连接。但是,有时候Client端重新发送请求不是因为数据报丢失了,而是有可能数据传输过程因为网络并发量很大在某结点被阻塞了,这种情形下Server端将先后收到2次请求,并持续等待两个Client请求向他发送数据…问题就在这里,Cient端实际上只有一次请求,而Server端却有2个响应,极端的情况可能由于Client端多次重新发送请求数据而导致Server端最后建立了N多个响应在等待,因而造成极大的资源浪费!所以,“三次握手”很有必要!

TCP断开连接图

这里写图片描述
为什么需要“四次挥手”?
  试想一下,假如现在你是客户端你想断开跟Server的所有连接该怎么做?第一步,你自己先停止向Server端发送数据,并等待Server的回复。但事情还没有完,虽然你自身不往Server发送数据了,但是因为你们之前已经建立好平等的连接了,所以此时他也有主动权向你发送数据;故Server端还得终止主动向你发送数据,并等待你的确认。其实,说白了就是保证双方的一个合约的完整执行!


Clever Internet Suite version 9.1 These Internet components give you everything you need to jumpstart your Internet development without any external dependencies. The suite of Internet Components contain over fifty components which are constantly refined and improved. The Clever Internet Suite components allow you to compose and parse messages in MIME format with multiple file attachments, build and send Web Form POST requests and many other features. The SMTP, POP3 and IMAP clients allow you to send and retrieve email messages over the Internet. All server components represent the fully functional multithreaded servers with the ability to customize the connection settings, support the most common protocols extensions. Using the Clever Internet Suite you can add instant SSL / TLS / SSH security to your Internet applications and implement many useful Internet-related features: Downloading, uploading and submitting of the Internet-resources. Sending and receiving e-mail messages with DKIM signatures. HTTP, FTP, SMTP, POP3, IMAP and NNTP client / server solutions. secure channel with X509 certificates support. OAUTH 2.0 authorization. SOAP Security and many more. In the new version 9.1 we have updated the MailMessage, SoapMessage and SFtp components, fixed issues in the TLS and cryptography engines. Starting from the version 8.0 the library was splitted on design-time and runtime packages. Starting from now, the components can be used by RAD Studio form designer in 64-bit projects. The basic socket components were replaced and improved. The class inheritance was changed. Please see the Help documentation for more details. The Help documentation is included to the Clever Internet Suite installation and also available at our website: Clever Internet Suite downloads What's new in version 9.1 The full RAD Studio 10.2 and 10.2.1 Tokyo support. MailMessage - RFC 5987 support added, file names in UTF-8 format implemented. New CryptEncoder component - provides methods for data encoding and decoding in PEM and SSH2 cryptographic formats. SFTP client - the public key authorization was implemented, the following new algorithms were added: diffie-hellman-group-exchange-sha256 and diffie-hellman-group14-sha1 for key exchange functionality; rsa-sha2-256 - server host key algorithm; aes256-ctr, aes192-ctr, aes128-ctr, aes256-cbc, aes192-cbc ,aes128-cbc - data encryption algorithms; hmac-sha2-256 - for message authentication algorithms; sha2-256 - hash calculation algorithms. DKIM component - the Config property was added. This property allows you to configure the used encryption and signature algorithms. The signature verification is disabled when retrieving the message header. HTTP client - the TLS1.2 option was enabled by default. EPP server - the UTF-8 encoding was added. All TCP-based server components (SMTP, POP3, IMAP4, FTP, etc.) - the new CharSet property allows you to specify the desired character encoding for received commands and server responses. All UDP-based client components (DNS query, etc.) - the new CharSet property allows you to specify the desired character encoding transmitted datagrams. HTTP request component - was redesigned, the Items indexed property now represents the HTTP request items collection object. The source code structure was changed. starting from now, the sources are placed in the following folders: common, design, packages, resources and ssh. To compile the source code project, navigate to the packages folder, choose the corresponding IDE version subfolder, e.g., D102 for Delphi 10.2 Tokyo, open and compile both the clinetsuite_102.dproj and dcl_clinetsuite_102.dproj projects. Finally, install dcl_clinetsuite_102.dproj to your RAD Studio IDE. The SSH and SFTP component files were moved to the main clinetsuite package. The clinetsuitessh package was removed from the installation. Implemented Features HTTP RIO component with SOAP Security support. Simple HTTP Server component. Complete Client / Server solutions with full SSL / TLS support for FTP, SMTP, POP3 and IMAP4 protocols. TLS / SSL support for all protocol components. SSH support for the SFTP protocol. Royalty free licensing. Free Unlimited Email support. Fully-indexed help documentation. Delphi and C++Builder demos code. Send / receive HTTP requests in JSON format. International domain names for HTTP components. The ability to verify the client and server credentials and certificates. HTTP Client - HTTPS (SSL / TLS) protocol, NTLM and Negotiate authentication. FTP, SMTP, POP3, IMAP, NNTP clients - three new TLS modes - implicit, explicit and automatic. STARTTLS command support. NTLM authentication for all mail clients was added: POP3, SMTP, IMAP. When the UseSasl option enabled, these components automatically determine and use the most secured authentication method. POP3, SMTP clients - working with GMAIL service with OAUTH 2.0 authorization. Fully functional HTTP / HTTPS client. FTP Client - SSL / TLS support, the ability to set FTP file attributes and permissions were added. FTP FXP (Site to Site) transfer mode. FTP Server - custom events for all operations with files and directories on the server, the possibility to customize all file-related operations including compressing and uncompressing functionality. Virtual File System. Events for implementing the mail sending / receiving progress with the ability to interrupt the process. Creating self-signed certificates, working with any type of certificate store including current user stores, local machine stores, file stores, registry stores and so on. Creating and parsing email messages in any format with file Attachments and Embedded pictures, the ability to determine the attachment size before saving it to the disk. POP3, SMTP, IMAP4 servers - SSL / TLS support, NTLM, APOP and CRAM-MD5 authentication methods, File System message storage. POP3, SMTP and IMAP4 clients - SSL / TLS support, NTLM and CRAM-MD5 authentication methods. Web DAV - manages remote files and folders on a web server. DNS Query - queries a DNS server for records. This component can retrieve the mail exchange domain (MX records), resolve the host IP, retrieve the information about name servers and many other information from the DNS server. DNS Server - implements fully functional DNS server and allows you to both manage handed DNS zones and cache non-authoritative DNS records. SMTP Relay - implements a SMTP Relay agent. With SMTP relay, a mail message may pass through a number of intermediate relay or gateway hosts on its path from sender to recipient. HTML Parser - parse HTML Tags: links, images, tables, meta tags and many more. GZip compressor component - provides compressing / uncompressing feature when transmitting data over the Internet, storing data in to a file, database and many more. RSS client - is used for creating, retrieving, and editing RSS feeds. Email validation components - allow you to validate recipients email addresses, mailbox availability and also handle bounced emails. Trace Logger - provides logging functionality for storing debug information and tracing your code. Also a set of additional classes and components are available: Mail Message, HTTP Request, GZip compressor, MIME Encoder, S/MIME message, HTML Parser. All these components make the application development process easy and clean. You can use these components separately from the main protocol components with any other library and even with your own socket implementation. Please visit our site Clever Components to learn more about our products. Feel free to join our Mail List Subscription at Mail List Subscription and stay tuned. Fixed bugs The HttpAuthorization is not thread-safe - fixed. SFTP file permissions parsing errors were fixed, IsDir file attribute works correctly. Installer runs with errors on Windows XP - fixed. TLS engine - INCOMPLETE_MESSAGE error occurred - fixed. RSA key for RSA-SHA-256 algorithm was imported incorrectly - fixed. SFTP large directory listing errors, the problems with receiving of incloplete SSH packets was fixed. SOAP Signing takes a lot of time - fixed. DKIM - the signature verification should be disabled when retrieving the message header. UDP server and all descendant components: there were issues with starting of listening socket (the server was hanged) - fixed. MailMessage - the message attachments and images lists were not automatically updated in the helper properties (Images, Attachments) when adding or deleting the body from the Bodies collection - fixed. MailMessage - the header fields with mixed encoding style were decoded incorrectly - fixed. DNS Server - some fixes in the server engine. IMAP client - the AppendMessage method did not work with GMail IMAP - fixed. FTP client - the file names with international symbols were obtained incorrectly - fixed. HTTP client - the resource URLs were not escaped - fixed. All HTTP clients (TclHttp, TclWebDav, TclDownloader, TclMultiDownloader, TclNewsChecker, TclWebUpdate) - the components incorrectly provided a list of supported compression algorithms - fixed. FTP server - the directory navigation worked incorrectly in case if the root folder is the root of the disk (e.g, c:\). The connected client cannot get back to the root folder after navigating to a subfolder - fixed. Known problems and restrictions FTP client and server - data connection uses IpV4 protocol only. Socks5 firewall - supports IpV4 only. The HTTP RIO component is available only starting from Delphi 2005 / C++Builder 2006. The SOAP encryption is available only on Win32 platform. The SOAP encryption requires an external library clcryptext.dll that is included to the Clever Internet Suite installation. This library represents managed code that is wrapped by Win32 functions. The source code for this library can be downloaded separately at www.clevercomponents.com website.
《Clever Internet Suite v10 完整源代码解析》 Clever Internet Suite v10 是一款强大的互联网开发工具包,提供了全面的网络组件和功能,适用于开发人员构建高效的网络应用。这款工具集包含了多种核心组件,如HTTP/HTTPS客户端、FTP/FTPS客户端、SMTP/POP3/IMAP邮件处理组件等,极大地简化了网络编程的复杂性。 1. HTTP/HTTPS客户端:Clever Internet Suite 提供的HTTP/HTTPS客户端组件能够帮助开发者轻松地进行网页抓取、数据下载或上传任务。它支持各种HTTP方法,如GET、POST、PUT等,并且具备处理Cookie、代理服务器、SSL/TLS加密的能力,使得开发者可以安全地访问HTTPS网站。 2. FTP/FTPS客户端:对于文件传输需求,Clever Internet Suite 提供了FTP/FTPS客户端组件,支持标准的FTP协议以及更安全的FTPS(FTP over SSL/TLS)。这使得开发者可以在不泄露敏感数据的情况下进行文件上传和下载操作。 3. SMTP/POP3/IMAP邮件处理:在电子邮件处理方面,该工具集涵盖了SMTP、POP3和IMAP协议的实现,允许程序发送和接收邮件,管理邮件箱,甚至支持邮件过滤和搜索功能。这对于构建企业级的邮件服务或自动化邮件处理系统非常有帮助。 4. 源代码全量:"FULL SOURCE" 标签表明,Clever Internet Suite v10 提供了完整的源代码,这意味着开发者不仅可以使用这些组件,还能深入理解其内部工作原理,进行自定义修改或扩展,以适应特定项目的需求。 5. WebUpdApp.exe:这个压缩包中的WebUpdApp.exe可能是一个更新应用程序,用于检查和安装Clever Inte
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值