I know this question seems typical and answered several times, but I think that if you read the details, this is not so often (I did not find it).
The fact is that I am developing a unix service in c that opens a socket and waits for connections, when I have a connection I create a new process to handle it , so there can be several connections open simultaneously .
int newfd = accept(sockfd, (struct sockaddr *)&clientaddr, (socklen_t*)&clientaddr_size);
Later ( after and inside some other methods and code) the child process save the connection information with BBDD, and I also need at this exact moment to get the IP address that opened the processed connection.
There can be several connections at the same time , and the struct sockaddr_in clientaddr variable that I pass to the accept method is used for the whole process. I'm not sure that later it is a good idea to get information about the IP address from this path, because then I could get IP address from another open connection .
I would like to be able to access the IP address from the file descriptor of the int newfd file that I get from the accept method (return integer). Is it possible? Or did I misunderstand the file descriptor function?
c unix file-descriptor fork sockets
Aleix
source share