I'm writing simple server/client and trying to get client IP address and save it on server side to decide which client should get into critical section. I googled it several times but couldn't find proper way to get IP address from sock structure.
I believe this is a way to get IP from sock struct after server accept request from client. More specifically in c after server execute
csock = accept(ssock, (struct sockaddr *)&client_addr, &clen)
Thanks
str
buffer toinet_ntop()
. Andsin_addr
is a struct - one has to usesin_addr.s_addr
. Worth noting that IPv4 address is stored in network byte order and to see it as a hex number one would need to usentohl(pV4Addr->sin_addr.s_addr)
. – Xylo