linux中关于socket通讯获取本地的源端口号的实现方法


当前第2页 返回上一页

终端1: 编译及运行


1

2

3

4

$ g++ source_port.cpp

$ ./a.out www.baidu.com

connect to www.baidu.com success.

local port: 39702

终端2: 通过tcpdump抓包验证


1

2

3

4

5

6

7

$ sudo tcpdump host www.baidu.com -v

tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes

18:38:32.381448 IP (tos 0x0, ttl 64, id 35033, offset 0, flags [DF], proto TCP (6), length 60)

icentos.39702 > 220.181.111.188.http: Flags [S], cksum 0x8cd2 (incorrect -> 0x596a), seq 2381397554, win 29200, options [mss 1460,sackOK,TS val 3513497323 ecr 0,nop,wscale 7], length 0

18:38:32.425904 IP (tos 0x0, ttl 55, id 35033, offset 0, flags [DF], proto TCP (6), length 60)

220.181.111.188.http > icentos.39702: Flags [S.], cksum 0xc315 (correct), seq 3561856904, ack 2381397555, win 8192, options [mss 1424,sackOK,nop,nop,nop,nop,nop,nop,nop,nop,nop,nop,nop,wscale 5], length 0

18:38:32.425930 IP (tos 0x0, ttl 64, id 35034, offset 0, flags [DF], proto TCP (6), length 40)

对比终端一和终端二表明获取的源端口地址是正确的。

总结

以上就是linux中关于socket通讯获取本地的源端口号的实现方法的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

linux怎么查看防火墙是否关闭了

linux常见错误及解决办法分享

如何在自行配置环境和安装软件时使用云市场镜像创建实例

linux中如何同步设置ntp服务器时间的详解

linux查看ssh是否开启

查看日志的linux命令是什么?

linux中iptables原理的图文详解

linux如何为用户添加root权限

使用linux创建ga1实例以及注意事项

linux如何配置ip

更多相关阅读请进入《Socket》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...

    暂无评论...