-
June 3rd, 2023, 07:05 AM
#1
socket and IP address client
I'm developing networking distributed software in Ansi C and server will receive several "connect" from different kinds of clients which make different kind of requests.
I need to save IP address of clients which make specific requests (according to protocol content) but in accept call I'd like to avoid to collect all IP address of all client request because only some of them will be useful.
I'd like to capture client IP address during recv stage but in this way I know only the socket descriptor, is there way to get ip address client if I know only socket id?
Server can to contact client.
-
June 4th, 2023, 01:50 AM
#2
Re: socket and IP address client
 Originally Posted by man page
recv(sockfd, buf, len, flags);
is equivalent to
recvfrom(sockfd, buf, len, flags, NULL, NULL);
Where
Code:
ssize_t recv(int sockfd, void *buf, size_t len, int flags);
ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,
struct sockaddr *src_addr, socklen_t *addrlen);
If you really want to know who sent the message, just use recvfrom.
-
June 4th, 2023, 07:33 AM
#3
Re: socket and IP address client
 Originally Posted by zio_mangrovia
I need to save IP address of clients which make specific requests (according to protocol content) but in accept call I'd like to avoid to collect all IP address of all client request because only some of them will be useful.
I'd like to capture client IP address during recv stage but in this way I know only the socket descriptor
How about getpeername function?
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|