跟踪 Linux 套接字调用?
我有一个正在尝试调试的 Python 库(pyzeroconf)。下面的代码返回“34”,就好像数据是通过套接字发送的,但我在两台不同的配备有wireshark的PC上看不到这些数据包。
bytes_sent = self.socket.sendto(out.packet(), 0, (addr, port))
我现在需要了解调用堆栈中发生了什么。有没有办法追踪正在发生的事情?
解决方案:问题与库默认的“绑定地址”有关。不允许使用值“0.0.0.0”,并且会静默失败(至少在 Linux 上)。
I've got a Python library I am trying to debug (pyzeroconf). The following code returns '34' as if the data was sent down the socket but I can't see those packets on 2 different wireshark equipped PCs.
bytes_sent = self.socket.sendto(out.packet(), 0, (addr, port))
I am at the point where I need to understand what's going on down the call stack. Is there a way to trace what's happening?
Resolution: the problem was related to the "bind address" the library was figuring out as default. A value of "0.0.0.0" isn't allowed and fails (at least on Linux) silently.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以使用
strace
,例如you can use
strace
, e.g.我很确定这不是您所期望的,但可以提供帮助:
strace -f -F python myscript.py
strace 转储通用程序的系统调用。
I'm quite sure this not what you expect, but can help:
strace -f -F python myscript.py
strace dump the system calls of a generic program.
为什么 INADDR_ANY IP 地址会失败?不应该。从我的角度来看,你的照片中还缺少其他东西。如果您尝试使用 (errno, string) 获取更具描述性的错误消息(代码块除外),会发生什么情况。
Why would the INADDR_ANY IP address fail? It shouldn't. From my point of view, something else is missing in your picture. What happens if you try, except the code block, using (errno, string) to get a more descriptive error msg.