getpeername always gives bad file descriptor

后端 未结 1 1451
孤街浪徒
孤街浪徒 2021-01-26 03:57

I have the following code, that i am trying to use to get the address of the other end of the socket, but getpeername() always fails with bad file descriptor<

相关标签:
1条回答
  • 2021-01-26 04:14

    socket descriptor is not shared between two processes. the captured socket descriptor is only effective in the traced process, and not effective in the tracer process. that's why getpeername complains bad descriptor.
    from the manual of ptrace:
    The ptrace() system call provides a means by which a parent process may observe and control the execution of another process, and examine and change its core image and registers. It is primarily used to implement breakpoint debugging and system call tracing.
    there's no word says they share process space, thus, they can not share socket descriptors, memory address, etc..

    0 讨论(0)
提交回复
热议问题