Getting remote ip address


#1

hi.

i create a tcp server socket and this socket is listening and waiting clients to connect.

Now i want to know how i can get the ip address and other informations(if any) of connected client.

i want to get this ip address so that i can control wheather this client has right to connect to me or not.


#2
void evh( wip_event_t *ev, void *ctx) {
   switch( ev->kind) {
   case WIP_CEV_OPEN: {
      char addrBuffer[16];
      u16 port;
      wip_getOpts( ev->channel,
                   WIP_COPT_PEER_STRADDR, addrBuffer, sizeof( addrBuffer),
                   WIP_COPT_PEER_PORT, & port,
                   WIP_COPT_END);
      wip_debug( "Connected to port %i at address %s\n", port, addrBuffer);
   }
   break;
   }
}

#3

but that only tells you the Peer’s IP address once it has connected

I don’t think there’s any way to block a specific IP address, or to allow only a specific IP address :question:


#4

No there isn’t any way to refuse connections on a per-peer-address basis. In POSIX terms, WIP performs the accept() automatically as soon as the select() returns. This might change if actual POSIX APIs are eventually added.

The closest think you can do is to bind the TCP listen socket to a specific local interface, but it will only do the trick for pretty specific cases.


#5

i think we can close the connection with wip_close() if the client ip address is in the black list. So we block it this way right? thanks for the reply.

An other thing. I look up edLib document which is an add-on library for Open AT 3.10. There is something about ed_SocketSetUpParams_t type. It says " For a server TCP Session, TcpServ parameter is used to apply filtering of incoming TCP requests from a remote destination IP address. Only requests from configured IP address will be allowed to connect to the Wavecom module. In case of no filtering this must be set to 255.255.255.255 value."
I think edlib automaticly bans the ip addresses except configured one.


#6

Perhaps it does - but note that edlib was discontinued some time ago, and is no longer supported…