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<
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..