void                proc_sig();
void                do_timer();
void                my_perror();
client              *find_client();
vat_client          *find_vat_client();
vat_client          *new_vat_client();
client              *open_connection();
int                 get_type();
slist               *unlink_slist();
client              *unlink_client();
short               get_client_id();
void                hold_down_client();
void                delete_client();
client              *unlink_client();
void                free_client();
client              *get_client();
void                free_slist();
slist               *get_slist();
void                remove_some_clients();
void                write_cmsg();
void                write_close();
void                write_pkt();
void                vat_id();
void                distribute();
void                distribute_audio();
client              *open_connection();
void                continue_connection();
void                update_client();
void                mbone_pkt();
VideoPacketHeader   *make_open_continue();
SiteId              *find_site_vms();
SiteId              *find_site_idlist();
void                update_vms_times();
VatMixerSpeaker     *delete_vms_member();
VatMixerSpeaker     *add_vms_member();
void                update_vms_list();
void                send_mixer_open_continues();
void                send_nv_ocp();
VideoPacketHeader   *nv_to_cuseeme();
void                delete_vat_client();
void                send_vat_idlist();
unsigned long       RTPTime();
void                distribute_nv();
short               send_to_nv();
void                check_restricted_senders();

#ifdef __MAIN__

client *chead = NULL;                         /* ptr to the active client list             */
client *clfree = NULL;                        /* ptr to the free client list               */

slist *sfree = NULL;                          /* ptr to the free slist list                */

short cfree_cnt,sfree_cnt;                    /* # of free clients and slists              */

vat_client *mhead = NULL;                   /* global ptr to the maven client list       */

unsigned long restrict_list[MAXCLIENT];       /* list of IP addrs if this reflector        */
short restrict_cnt = 0;                       /* is restricted                             */

unsigned long admit_senders[MAXCLIENT];       /* list of IP addrs allowed to send          */
short admit_cnt = 0;                          /* count of the above                        */

unsigned long deny_list[MAXCLIENT];           /* list of IP addrs to deny connectivity to  */
short deny_cnt = 0;                           /*                                           */

unsigned long tmp_deny_list[MAXCLIENT];       /* list of IP addrs to temporarily deny connectivity to  */
unsigned short tmp_deny_wait[MAXCLIENT];      /* wait time for entires on the tmp_deny_list */

unsigned long bcc_server_list[MAXSRCREF];     /* list of Blind Carbon Copy Servers, from   */
unsigned long bcc_server_list_id[MAXSRCREF];  /* conference ID's for the BCC Servers       */
short bcc_srv_cnt = 0;                        /* whom we are to get video from             */

unsigned long bcc_client_list[MAXSRCREF];     /* list of Blind Carbon Copy Clients, to     */
short bcc_clt_cnt = 0;                        /* whom we are to give video to              */

unsigned long ref_ucast_list[MAXSRCREF];      /* list of unicast reflectors                */
short ref_ucast_cnt = 0;                      /* count of unicast reflectors               */

unsigned long send_to_nv_list[MAXNVSTREAMS];  /* list of addrs from which to send video to nv clients */
unsigned short send_to_nv_timer[MAXNVSTREAMS];/* send timer for the above addresses        */
short send_to_nv_cnt = 0;                     /* # of entries in the list                  */

char *tracefile;                              /* trace / log file name                     */
FILE *log_file;

short debug = 0;                              /* if 1, turn on debugging messages          */
short self_reflect = 0;                       /* if 1, reflect back to the send            */

short local_senders = 1;                      /* if 0, disallow local conferencing, used   */
                                              /* if this reflector is simply feeding a     */
                                              /* conference to all of it's clients         */

unsigned long control_ip = -1;                /* ip address for refmon                     */
unsigned long god_ip = -1;                    /* ip address for the conference god         */


int conference_id = 0;                        /* conference id                             */

int gbcc_cnt = 0;                             /* # of general BCC connections to allow     */
int gbcc_id = 0;                              /* conference id for the general BCC client  */

short timer_expired = 0;                      /* keep track of our timer                   */

int min_mac_version = 0;                      /* minimum mac version # required for this ref  */
int min_pc_version = 0;                       /* minimum pc version # required for this ref   */

int cap;                                      /* default maximum transmission cap          */


int hold_down = 30;                           /* default hold down 30 minutes              */

int vid_sock,cntrl_sock,msg_sock;             /* video socket, control                     */
                                              /* socket, and message socket for supporing  */
                                              /* the control socket                        */

struct sockaddr_in myaddr;                    /* my address                                */
int maxallowed;                               /* maximum # of clients allowed              */
int maxsenders = -1;                          /* maximum # of senders allowed              */
int maxlurkers = -1;                          /* maximum # of lurkers allowed              */

char conf_buf[CONFBUF];                       /* buffer for storing the config file        */
char motd_buf[MOTDBUF];                       /* buffer for storing the MOTD               */

char mp_buf[MSGBUF];                          /* buffer for max-participants error msg     */
char ms_buf[MSGBUF];                          /* buffer for max-senders error msg          */
char ml_buf[MSGBUF];                          /* buffer for max-lurkers error msg          */
char ci_buf[MSGBUF];                          /* buffer for conference-id error msg        */
char ad_buf[MSGBUF];                          /* buffer for admit error msg                */
char cap_buf[MSGBUF];                         /* buffer for cap error msg                  */
char mv_mac_buf[MSGBUF];                      /* buffer for min-mac-version error msg      */
char mv_pc_buf[MSGBUF];                       /* buffer for min-pc-version error msg       */
char dy_buf[MSGBUF];                          /* buffer for deny error msg                 */

short motd_len = 0;

int maven_port = 0;                           /* sockets for handling Maven clients        */
int maven_sock = 0;

int maven_cntl_sock = 0;
int maven_cntl_sock_out = 0;

int nv_ucast_port = 0;                        /* port for nv's unicasting to the reflector */
int nv_ucast_sock = 0;

unsigned short client_cnt = 0;                /* # of Mac/PC clients                       */
unsigned short nv_client_cnt = 0;             /* # of nv clients                           */
unsigned short send_ccnt = 0;                /* # of clients that are also video senders  */
unsigned short lurker_ccnt = 0;              /* # of clients that are just video lurkers  */

unsigned short bcc_client_cnt = 0;            /* # of BCC clients                          */
unsigned short bcc_gclient_cnt = 0;           /* # of BCC general clients                  */
unsigned short bcc_origin_cnt = 0;            /* # of BCC origins                          */
unsigned short bcc_server_cnt = 0;            /* # of BCC servers                          */

unsigned short ref1_server_cnt = 0;           /* # of REF1 servers                         */
unsigned short ref1_origin_cnt = 0;           /* # of REF1 origins                         */
unsigned short ref1_client_cnt = 0;           /* # of REF1 clients                         */

unsigned short ref2_server_cnt = 0;           /* # of REF2 servers                         */
unsigned short ref2_origin_cnt = 0;           /* # of REF2 origins                         */

unsigned short ref3_server_cnt = 0;           /* # of REF3 servers                         */
unsigned short ref3_origin_cnt = 0;           /* # of REF3 origins                         */

unsigned short vat_client_cnt = 0;          /* # of maven clients                        */


int log_limit = 10000;                        /* default log file line limit               */
unsigned long tick_cnt;                       /* # of times through the timer loop         */

char start_time[25];                          /* date and time when reflector was started  */

int vat_confid = 0;                           /* vat conference id.  This is the confid
                                                 needed to relay CUSM audio to MBone vats.
                                                 It is supplied by the config file.        */

int vat_port = 0;                             /* port for vat multicast clients            */
int nv_mcast_port = 0;                        /* port for nv multicast clients             */

struct sockaddr_in nv_out_mcast;              /* socket for sending to nv                  */
int nv_out_mcast_sock;

struct sockaddr_in nv_in_mcast;               /* socket for receiving from nv              */
int nv_in_mcast_sock;

struct sockaddr_in nv_inout_mcast;            /* socket for sending to and receiving from nv on a multicast address */
int nv_inout_mcast_sock;

struct sockaddr_in rfout_mcast;               /* socket for sending to other reflectors    */
int rfout_mcast_sock;

struct sockaddr_in rfin_mcast;                /* socket for receiving from other reflectors */
int rfin_mcast_sock;

struct sockaddr_in inout_mcast;               /* socket for sending and receiving from other reflectors */
int inout_mcast_sock;

struct sockaddr_in vat_in_mcast;              /* socket for receiving vat from a multicast address */
int vat_in_mcast_sock = 0;

struct sockaddr_in vat_out_mcast;             /* socket for sending to vat on a multicast address */
int vat_out_mcast_sock = 0;

struct sockaddr_in vat_inout_mcast;           /* socket for sending to and receiving from vat on a multicast address */
int vat_inout_mcast_sock = 0;

int vat_cntl_mcast_sock = 0;                  /* vat control socket -- analogous to maven_cntl   */

int nv_ttl,rf_ttl,inout_ttl,vat_ttl;          /* multicast ttl's                                 */

int nv_streams = 4;                           /* # of video streams to send to nv clients        */

unsigned char  buffer[MAXMSG];

unsigned long bytes_in, bytes_out;
unsigned long pkts_in, pkts_out;

#endif

#ifndef __MAIN__

extern client *chead;
extern client *clfree;

extern slist *sfree;

extern short cfree_cnt,sfree_cnt; 

extern vat_client *mhead;

extern unsigned long restrict_list[MAXCLIENT]; 
extern short restrict_cnt;

extern unsigned long admit_senders[MAXCLIENT];
extern short admit_cnt;

extern unsigned long deny_list[MAXCLIENT]; 
extern short deny_cnt;

extern unsigned long tmp_deny_list[MAXCLIENT];
extern unsigned short tmp_deny_wait[MAXCLIENT];

extern unsigned long bcc_server_list[MAXSRCREF];
extern unsigned long bcc_server_list_id[MAXSRCREF]; 
extern short bcc_srv_cnt;

extern unsigned long bcc_client_list[MAXSRCREF];
extern short bcc_clt_cnt;

extern unsigned long ref_ucast_list[MAXSRCREF];
extern short ref_ucast_cnt;

extern unsigned long send_to_nv_list[MAXNVSTREAMS];
extern unsigned short send_to_nv_timer[MAXNVSTREAMS];
extern short send_to_nv_cnt;                        

extern char *tracefile;  
extern FILE *log_file;

extern short debug;
extern short self_reflect;

extern short local_senders;
                         
extern unsigned long control_ip;
extern unsigned long god_ip;

extern int conference_id;
extern int gbcc_cnt;
extern int gbcc_now; 
extern int gbcc_id;

extern short timer_expired;

extern int min_mac_version;
extern int min_pc_version; 

extern int cap;          

extern int hold_down;

extern int vid_sock,cntrl_sock,msg_sock;

extern struct sockaddr_in myaddr;    
extern int maxallowed;              
extern int maxsenders;                              
extern int maxlurkers;                               


extern char conf_buf[CONFBUF];     
extern char motd_buf[MOTDBUF];    

extern char mp_buf[MSGBUF];      
extern char ms_buf[MSGBUF];      
extern char ml_buf[MSGBUF];      
extern char ci_buf[MSGBUF];     
extern char ad_buf[MSGBUF];    
extern char cap_buf[MSGBUF];  
extern char mv_mac_buf[MSGBUF];
extern char mv_pc_buf[MSGBUF];
extern char dy_buf[MSGBUF];  

extern short motd_len;

extern int maven_port;
extern int maven_sock;
extern int maven_cntl_sock;
extern int maven_cntl_sock_out;
extern int nv_ucast_port; 
extern int nv_ucast_sock;

extern unsigned short client_cnt;
extern unsigned short nv_client_cnt;
extern unsigned short send_ccnt;
extern unsigned short lurker_ccnt;

extern unsigned short bcc_client_cnt;
extern unsigned short bcc_gclient_cnt; 
extern unsigned short bcc_origin_cnt;
extern unsigned short bcc_server_cnt;

extern unsigned short ref1_server_cnt;
extern unsigned short ref1_origin_cnt;
extern unsigned short ref1_client_cnt;

extern unsigned short ref2_server_cnt;
extern unsigned short ref2_origin_cnt;

extern unsigned short ref3_server_cnt;
extern unsigned short ref3_origin_cnt;
extern unsigned short vat_client_cnt; 

extern int log_limit;
extern unsigned long tick_cnt;

extern char start_time[25];

extern int vat_port;
extern int nv_mcast_port;

extern struct sockaddr_in nv_mcast;
extern int nv_mcast_sock;

extern struct sockaddr_in nv_out_mcast;              
extern int nv_out_mcast_sock;

extern struct sockaddr_in nv_in_mcast;              
extern int nv_in_mcast_sock;

extern struct sockaddr_in nv_inout_mcast;          
extern int nv_inout_mcast_sock;

extern struct sockaddr_in rfout_mcast;
extern int rfout_mcast_sock;

extern struct sockaddr_in rfin_mcast; 
extern int rfin_mcast_sock;

extern struct sockaddr_in inout_mcast;
extern int inout_mcast_sock;

extern struct sockaddr_in inout_mcast;          
extern int inout_mcast_sock;

extern struct sockaddr_in vat_in_mcast;          
extern int vat_in_mcast_sock;

extern struct sockaddr_in vat_out_mcast;           
extern int vat_out_mcast_sock;

extern struct sockaddr_in vat_inout_mcast;          
extern int vat_inout_mcast_sock;

extern int vat_cntl_mcast_sock;                  

extern int nv_ttl,rf_ttl,inout_ttl,vat_ttl;          
extern int nv_streams;                           

extern unsigned char  buffer[MAXMSG];

extern unsigned long bytes_in, bytes_out;
extern unsigned long pkts_in, pkts_out;

extern int vat_confid;                           

#endif
