Linux:如何从特定端口发送 TCP 数据包? [英] Linux: how to send TCP packet from specific port?

查看:58
本文介绍了Linux:如何从特定端口发送 TCP 数据包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何打开用于从特定 TCP 端口发送的原始套接字?我希望我的所有连接始终来自临时端口以下的一系列端口.

How to open a raw socket for sending from specific TCP port? I want to have all my connections always go from a range of ports below ephemerals.

推荐答案

如果您使用 raw 套接字,那么只需在数据包头中填写正确的 TCP 源端口即可.

If you are using raw sockets, then just fill in the correct TCP source port in the packet header.

如果您使用的是 TCP 套接字接口(socket()connect() 和朋友),那么您可以通过调用bind() 客户端套接字的系统调用 - 与您所做的完全一样设置服务器套接字的监听端口.

If, instead, you are using the TCP socket interface (socket(), connect() and friends), then you can set the source port by calling the bind() system call for the client socket - exactly as you would to set the listening port for the server socket.

这篇关于Linux:如何从特定端口发送 TCP 数据包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆