简体   繁体   English

哪个 libc 函数保留一个端口号,以便操作系统不允许其他进程使用它?

[英]Which libc function reserves a port number so the OS won't allow other processes to use it?

I am writing a my first low-level networking application (a simple VPN) in rust and need to modify both the IP source address and TCP/UDP source port for each packet.我正在用 rust 编写我的第一个低级网络应用程序(一个简单的 VPN),并且需要修改每个数据包的 IP 源地址和 TCP/UDP 源端口。 Therefore I need to use raw sockets and don't get the added convenience of the OS reserving port numbers.因此,我需要使用原始套接字,并且不会获得操作系统保留端口号的额外便利。

How can I tell the OS to reserve a range of ports so that it won't assign them to other applications and create a conflict?我如何告诉操作系统保留一系列端口,以便它不会将它们分配给其他应用程序并造成冲突?

There is no way to tell the OS to "reserve" a port apart from associating it with a socket, ie create a socket and bind to the address and port.除了将端口与套接字相关联之外,没有办法告诉操作系统“保留”端口,即创建一个套接字并绑定到地址和端口。

Apart from that VPN are typically implemented by having a virtual network adapter like TUN/TAP with its own IP address and with appropriate routing to define which traffic should be passed through the VPN.除此之外,VPN 通常是通过拥有一个像TUN/TAP这样的虚拟网络适配器来实现的,它有自己的 IP 地址和适当的路由来定义哪些流量应该通过 VPN。 No address or port rewriting needs to be done in this case.在这种情况下,不需要进行地址或端口重写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM