www.beck-ipc.com

@CHIP-RTOS C Library - BIOS API


BIOS_Connection_Handler

Install a system server connection handler function.

int BIOS_Connection_Handler ( CONN_HANDLER handler,
                              SERVER_SPEC which_server );

Parameters

handler

Vector to callback function

which_server

Enumerator:
    SS_FTP_SERVER = 0
    SS_TELNET_SERVER = 1
    SS_WEB_SERVER = 2

    SC1x3/SC2x only:
    SS_SSL_WEB_SERVER = 3
    SS_SSH_SERVER = 4

Return Value

0:  Success
-1:  Invalid which_server parameter

Comments

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

A connection handler function must be declared in the following way:

int huge UserConnectionHandler(
                     struct sockaddr far *sockptr );



Example usage:

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.
A connection handler can be removed by calling BIOS_Connection_Handler with a null pointer for the handler parameter.

SC1x Comments

Example handler:
The handler can read the IP Address and the Port in the sockaddr_in struct . (If desired, the IP address in the sin_addr structure member can be converted to ASCII using the TCP/IP API_INETTOASCII function.)  

int huge UserConnectionHandler( struct sockaddr * SockAddr )
{
    char ip_str[INET_ADDRSTRLEN];
    InetToAscii(&((struct sockaddr_in *)SockAddr)->sin_addr.s_addr
                ,ip_str);
    helper_printf("\r\nHost %s, Port %u",ip_str,
                ((struct sockaddr_in *)SockAddr)->sin_port);
    return 0;
}

SC1x3/SC2x Comments

Example handler:
The handler can read the IP Address and the Port in the sockaddr_storage struct . Both address modes IPv4 and IPv6 are supported.

            
int huge 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;
}

See Also

RTOS API

This library function invokes a RTOS software interrupt.   Refer to this RTOS API function's documentation for more details.

Supported since or modified in @CHIP-RTOS version

    SC12SC13SC11SC1x3SC2x
    V1.02V1.00V1.00V0.90V1.00

This API List
List of C Libraries
@CHIP-RTOS Main Index


End of document