#define         _XOPEN_SOURCE

#define	LOGFILE	"/var/log/trust.log"

#include        <stdio.h>
#include        <stdlib.h>
#include        <malloc.h>
#include        <string.h>
#include        <errno.h>
#include        <signal.h>
#include        <fcntl.h>
#include	<unistd.h>
#include        <sys/types.h>
#include        <sys/socket.h>
#include        <netinet/in.h>
#include        <netdb.h>
#include        <sys/stat.h>
#include        <sys/param.h>
#include        <sys/time.h>
#include        <sgtty.h>
#include        <arpa/inet.h>
#include	<sys/ipc.h>
#include	<sys/shm.h>
#include	<time.h>

#define timercmp(a, b, CMP) \
 (((a)->tv_sec == (b)->tv_sec) ? \
  ((a)->tv_usec CMP (b)->tv_usec) : \
  ((a)->tv_sec CMP (b)->tv_sec))


// 足縷A~W邂~W縷C~^縷Bｯ縷Cｭ
#define timeradd(a, b, result) \
  do { \
    (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
    (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
    if ((result)->tv_usec >= 1000000) \
      { \
        ++(result)->tv_sec; \
        (result)->tv_usec -= 1000000; \
      } \
  } while (0)

// 蠑~U縷A~M邂~W縷C~^縷Bｯ縷Cｭ
#define timersub(a, b, result) \
  do { \
    (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
    (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
    if ((result)->tv_usec < 0) { \
      --(result)->tv_sec; \
      (result)->tv_usec += 1000000; \
    } \
  } while (0)


int	login (int Socket);
void	NoRoute(void);
void	insEntry(void);

char	RepeaterCall[8];
char	TrustName[16];
struct	in_addr	RepeaterIP;
struct	in_addr	dbIP;
struct  sockaddr_in     db_in;

int	Acc;
int	Soc;
int	shm_id;
int	TrustDB_in;
int	TrustDB_out;
int	cmdmode;
int	cmdin;

char	TrustDbDomainName[128];
char	MonitorDomainName[128];

in_port_t	Port;
in_port_t	AuthPort;
in_port_t	dbInPort;
in_port_t	dbOutPort;
in_port_t	MonitorPort;

FILE	*logfile;
time_t	now;

