IPC@CHIP® RTOS-PPC – API Documentation

Header image

Main page


int RegisterSrvConnCbHandler ( void *  userConnectionCbFuncPtr,
int  server 
)

Install a system server connection handler function.
The installed connection handler will be executed by the TCPIP protocol stack if a client establishes a connection to the server (FTP, WEB, Telnet, SSL Webserver, SSH Server).

Parameters:
[in] server See enumeration type SERVER_SPEC
[in] userConnectionCbFuncPtr Pointer to user's callback function.
Returns:
0 : success
-1: Invalid server parameter
Note:
A connection handler function must be declared in the following way:
 int  userConnectionHandler(struct sockaddr *sockptr );
The function will be automatically uninstalled, if the application exits.

The implemented handler function could check the source IP address (Client's IP), comparing this IP with an application internal list of allowed IP addresses and reject the connection by returning a non-zero value if the source IP is not in the list.
If the connection handler returns zero the connection will be established. If it returns a non-zero value, the connection will be aborted.
Example:
int UserConnectionHandler( struct sockaddr * SockAddr )
{
  char ip_str[INET6_ADDRSTRLEN];
  struct sockaddr_in ipv4SockAddr;

  if(IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_storage *)SockAddr)->addr.ipv6.sin6_addr))
  {
    // IPv4, copy data into  sockaddr_in variable
    ipv4SockAddr.sin_addr.s_addr = ((struct sockaddr_storage *)SockAddr)
                                     ->addr.ipv6.sin6_addr.ip6Addr.ip6U32[3];
    ipv4SockAddr.sin_port        = ((struct sockaddr_storage *)SockAddr)
                                     ->addr.ipv6.sin6_port;
    // Convert to string
    inet_ntop(AF_INET,
              &ipv4SockAddr.sin_addr,
              ip_str,
              INET_ADDRSTRLEN);
 
    //helper_printf(.........);
  }
  else
  {
    // IPv6: //Convert to string
    inet_ntop(AF_INET6,
              &((struct sockaddr_storage *)SockAddr)->addr.ipv6.sin6_addr,
              ip_str,
              INET6_ADDRSTRLEN);

    //helper_printf(...........);
  }
  return 0;
}
Since:
SC2x3 V1.00 - CLIB V1.00





Top of page | Main page

Copyright © 2018 Beck IPC GmbH
Generated on Thu Nov 1 13:20:17 2018 by Doxygen 1.6.1