Annotation of 43BSDReno/sys/nfs/TEST/billboard/src/bb_ip.c, revision 1.1

1.1     ! root        1: /*
        !             2:  ******************************************************************************
        !             3:  *
        !             4:  * Module: bb_ip.c
        !             5:  *
        !             6:  * Functions: 
        !             7:  *         bb_get_ip_lines()   - Interpret a string to contain IP addresses.
        !             8:  *                             - Place the addresses in the IP array and
        !             9:  *                             - return the number found and index of first.
        !            10:  *         bb_check_ip()       - Check if the IP address of the caller is
        !            11:  *                             - in the IP list of his specified id name.
        !            12:  *
        !            13:  *
        !            14:  ******************************************************************************
        !            15:  */
        !            16: 
        !            17: /*
        !            18:  ******************************************************************************
        !            19:  * Include Files
        !            20:  ******************************************************************************
        !            21:  */
        !            22: #include <stdio.h>
        !            23: #include <rpc/rpc.h>
        !            24: #include "common.h"
        !            25: #include "protocol.h"
        !            26: #include "server.h"
        !            27: 
        !            28: char   *strtok();
        !            29: void   bb_get_ip();
        !            30: 
        !            31: 
        !            32: 
        !            33: /*************************************************************************
        !            34: **                                                                     **
        !            35: **  get_ip_lines() - Interpret the input 'line' to be a list of internet**
        !            36: **  addresses.  Place them in the internet table and return the starting**
        !            37: **  index of this block as well as the number of addresses in the block.**
        !            38: **                                                                     **
        !            39: *************************************************************************/
        !            40: BB_ip          bb_ips[BB_MAX_IP];      /* IP Address array.            */
        !            41: int            bb_ip_count;            /* The number of IP's in array. */
        !            42: 
        !            43: void
        !            44: bb_get_ip_lines( line, p_count, p_index)
        !            45:   char *line;          /* The input line of IP address tokens.         */
        !            46:   int  *p_count;       /* Output number of IP addresses in the block.  */
        !            47:   int  *p_index;       /* The starting index of the block of IP addrs. */
        !            48: {
        !            49:     char       *ip_addr;       /* Points to ip address string.         */
        !            50: 
        !            51:     /*
        !            52:     **  The index of this block of ip addresses is equal to the count.
        !            53:     */
        !            54:     *p_index = bb_ip_count;
        !            55:     *p_count = 0;
        !            56: 
        !            57: 
        !            58:     if ( (ip_addr = strtok( line, BB_IP_SEPARATOR)) == NULL )
        !            59:     {
        !            60:        fprintf( stderr, "ERROR: Null IP address list in data file.\n");
        !            61:     }
        !            62: 
        !            63:     do
        !            64:     {
        !            65:        strncpy( bb_ips[bb_ip_count++], ip_addr, BB_IP_ADDR_LEN);
        !            66:        (*p_count)++;
        !            67:     }
        !            68:     while ( (ip_addr = strtok( NULL, BB_IP_SEPARATOR)) != NULL );
        !            69: 
        !            70:     /*
        !            71:     **  Strtok() leaves the \n on the last IP addres, take it off.
        !            72:     */
        !            73:     bb_ips[bb_ip_count -1][strlen(bb_ips[bb_ip_count-1])-1] = NUL;
        !            74: }
        !            75: 
        !            76: 
        !            77: /*************************************************************************
        !            78: **                                                                     **
        !            79: **  bb_check_ip() - This function checks to see if the client has an   **
        !            80: **  entry in the ip list which matches the ip address of this call.    **
        !            81: **                                                                     **
        !            82: *************************************************************************/
        !            83: int
        !            84: bb_check_ip( client)
        !            85:   BB_id                client;         /* The clients identifier.              */
        !            86: {
        !            87:     int                client_id;      /* The index of the client.             */
        !            88:     BB_co_data codata;         /* The company data of the client.      */
        !            89:     int                i;              /* Nice loop variable name.             */
        !            90:     BB_ip      ip;             /* The ip address of the caller.        */
        !            91: 
        !            92:     /*
        !            93:     **  Get the client's id.
        !            94:     */
        !            95:     if ( (client_id = bb_get_hash( client)) == BB_HASH_ID_NOT_FOUND )
        !            96:     {
        !            97:        return BB_BAD_CLIENT;
        !            98:     }
        !            99: 
        !           100:     /*
        !           101:     **  Get the company data of the client.
        !           102:     */
        !           103:     if ( bb_get_codata( client_id, &codata) != BB_SUCCESS )
        !           104:     {
        !           105:        return BB_BAD_CLIENT;
        !           106:     }
        !           107: 
        !           108:     /*
        !           109:     **  Get the ip address of the caller and check it agains the
        !           110:     **  clients list of ip addresses.
        !           111:     */
        !           112:     bb_get_ip( ip);
        !           113:     for( i = codata.ip_idx; i < codata.ip_idx + codata.ip_cnt; i++ )
        !           114:     {
        !           115:        if ( strncmp( bb_ips[i], ip, BB_IP_ADDR_LEN) == 0 )
        !           116:        {
        !           117:            return BB_SUCCESS;
        !           118:        }
        !           119:     }
        !           120: 
        !           121:     return BB_FAILURE;
        !           122: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.