Menu

how to know client IP

Help
2008-12-15
2013-04-24
  • Awais Abbasi

    Awais Abbasi - 2008-12-15

    i have made a server
    which has few functions

    i want to know whats the client IP whenever some client calls a function at server

    how can i get client IP in  function at server

     
    • Awais Abbasi

      Awais Abbasi - 2008-12-18

      anybody here
      waiting for your reply

       
    • quique123

      quique123 - 2009-02-23

      In the current stand, there is not way to know the client IP inside an execute call, but, hey, we are talking about a C++ DLL.

      These are a few ideas you can implemente, but not all tested and do not know if it is the better design. Anyway, notice that:
      1. Executing a server method needs to call child classes of XmlRpcServerMethod, i.e, MyMethodXmlRpcServerMethod
      2. Each XmlRpcServerMethod object has a reference to the XmlRpcServer object
      3. But the client information is part of the XmlRpcServerConnection class. As parameter of this class constructor, it is the connection socket.
      4. Objects of XmlRpcServerConnection are created by connection incoming
      5. When a XML RPC message comes into a server connection object, it looks for the matching method and call the 'execute' function

      you can do following:
      1. Create a child of XmlRpcServerConnection, i.e. XmlServerConnectionIPStoring. Use the same constructor as XmlRpcServerConnection and add one more data attribute, called std::string peerIP. When an object is instansiated (using the constructor), use getpeername and inet_ntoa to get the client IP
      2. To let the method object know with server client call it, you can use the following:
        2.1. Create a child of XmlRpcServerMethod, i.e. XmlRpcServerMethodWithIP, with one more attribute called clientIP. Then, you can create a function XmlRpcServerMethodWithIP::setClientIP.
        2.2. In XmlServerConnectionIPStoring, overload the method executeMethod. Add the call to XmlRpcServerMethodWithIP::setClientIP.
        2.3. All children of XmlRpcServerMethodWithIP (i.e. MyMethodXmlRpcServerMethodWithIP) can in the ::execute method access the value of the clientIP value

      It sounds much more complicated as (IMHO) it is

      Let me know if you need more inputs and if you implement the feature or not

      Quique

       
    • Awais Abbasi

      Awais Abbasi - 2009-08-06

      thanks for the reply
      i am getting back to this topic after a long time
      i will let you know and post code here if i am able to do it

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.