CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2018
    Posts
    158

    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.

  2. #2
    Join Date
    Nov 2018
    Posts
    122

    Re: socket and IP address client

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

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,402

    Re: socket and IP address client

    Quote Originally Posted by zio_mangrovia View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured