确定TCP端口号的客户端得到了束缚 [英] Determining the TCP port number to which client got bound

查看:121
本文介绍了确定TCP端口号的客户端得到了束缚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个TCP套接字而没有关于端口号绑定到[socket.sin_port = 0。但是后来,如果我想打印客户端的端口号,我该怎么做呢?客户机C应用程序(在Linux上)创造了许多客户当中去连接到服务器。要调试问题,我捕捉空灵的流量。我想打印在日志中的端口号,而问题的出现等等空灵的过滤变得容易。

I create a TCP socket without bothering about the port number to bind to [socket.sin_port = 0]. However later on if I want to print the port number of client how do I do that? The client C application (on Linux) creates many clients which get connected to server. To debug issues I capture the traffic on ethereal. I thought of printing the port number in logs while issue arises so that filtering on ethereal becomes easy.

任何帮助将是AP preciated。

Any help would be appreciated.

-Prabhu

推荐答案

使用的getsockname()调用连接成功后获得套接字地址和端口。

Use the getsockname() call to get the socket address and port after a successful connection.

编辑:正确的方法名。有时候,我不能从一个窗口复制一个简单的词来喽!

correct method name. Sometimes I can't copy a simple word from one window to another!

这篇关于确定TCP端口号的客户端得到了束缚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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