/*--------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <signal.h>
#include <time.h>
/*--------------------------------------*/
#define ADMINPORT 60000
#define LOGFILE "admin.log"
#define BACKLOG 10
#define GRP_LEN 3
#define ADDR_LEN 15
#define MSG_LEN 1024

typedef enum e_msgs {
  GRP_QUERY=0x01,
  GRP_REPLY=0x02,
  REG_QUERY=0x03,
  REG_REPLY=0x04,
  GM_RESIGN=0x05
} msg_type;

typedef struct grp_query {
  unsigned char type;
  unsigned char grp[3];
} grp_query_msg;

typedef struct grp_reply {
  unsigned char type;
  unsigned char grp[3];
  unsigned char addr[15];
} grp_reply_msg;

typedef struct reg_query {
  unsigned char type;
  unsigned char grp[3];
  unsigned char addr[15];
} reg_query_msg;

typedef struct reg_reply {
  unsigned char type;
  unsigned char flag;
  unsigned char grp[3];
  unsigned char addr[15];
} reg_reply_msg;

typedef struct gm_resign {
  unsigned char type;
  unsigned char grp[3];
} gm_resign_msg;
/*--------------------------------------*/

/*--------------------------------------*/
void Open_Socket(int*);
void Wait_For_Connect_Request(int);
void Reaper();
void SIGCHLD_Handler(int);
void Service_Connection_Request(int);
void Handle_Msg(unsigned char*,unsigned char*,int,FILE*);
FILE* Is_File(unsigned char*);
int Is_Member(FILE*,char*);
int GM_Select(FILE*,unsigned char*,char*,int);
void Report_GM_To_Requestor(int,unsigned char*,unsigned char*);
char* Get_Time_String(char*);
void Err_Exit(char*);
void Send_Reg_Reply (unsigned char,unsigned char*,\
		     unsigned char*,unsigned char*,int);
void Remove_GM (FILE*,int);
/*--------------------------------------*/
