//
// @(#) $Header: /opt/ntp/timelord/shm/RCS/ntpscon.h,v 2.0.0.6 2006/06/16 00:53:28 skia Exp $
// @(#) NTP Socket connector definitions
//
// @(#) This software is relased under the GPL and
// @(#) is Copyright (C)GS3 Technologies Inc. 2000-2006
// @(#) For updates check: http://www.gs3tech.com/
//
#include "sockhelp.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <syslog.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include <ctype.h>
#include <sys/mman.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <getopt.h>

//
// global defines
//
#define CFILE1 "/etc/ntp.oncore0"
#define CFILE2 "/etc/ntp.oncore.0"
#define CFILE3 "/etc/ntp.oncore"
typedef unsigned char uchar;

struct Msg {
	char c[5];
	unsigned int seq;
};

struct Msg Hdr[] = {
	//
	// GT + UT commands
	// 
	{"@@Aa", 0}, {"@@Ab", 0}, {"@@Ac", 0}, {"@@Ad", 0},
	{"@@Ae", 0}, {"@@Af", 0}, {"@@Ag", 0}, {"@@Ao", 0},
	{"@@Ap", 0}, {"@@Aq", 0}, {"@@Aw", 0},
	{"@@Bb", 0}, {"@@Be", 0}, {"@@Bj", 0},
	{"@@Cb", 0}, {"@@Cf", 0}, {"@@Cj", 0},
	{"@@Ea", 0},
	{"@@Fa", 0},
	{"@@Sz", 0},
	//
	// GT Only
	//
	{"@@AN", 0}, {"@@AO", 0}, {"@@Au", 0}, {"@@Av", 0},
	{"@@Bf", 0},
	{"@@Ce", 0}, {"@@Ci", 0},
	{"@@Eq", 0},
	//
	// UT Only
	// 
	{"@@AP", 0},
	{"@@As", 0},
	{"@@At", 0},
	{"@@Az", 0},
	{"@@Ay", 0},
	{"@@Bo", 0},
	{"@@En", 0},
	//
	// VP/XT and Basic V8.8 Only
	// 
	{"@@Ax", 0}, {"@@Bn", 0}, {"@@Cd", 0}, {"@@Fd", 0},
	{"@@An", 0}, {"@@AB", 0}, {"@@Aj", 0}, {"@@AJ", 0},
	{"@@Bc", 0}, {"@@Ec", 0}, {"@@AA", 0}, {"@@Bi", 0},
	{"@@Bk", 0}, {"@@Ek", 0}, {"@@Ar", 0}, {"@@Cg", 0},
	{"@@Ba", 0}, {"@@Bg", 0}, {"@@Eg", 0}, {"@@Ai", 0},
	{"@@Ah", 0}, {"@@Ca", 0}, {"@@Cl", 0}, {"@@AC", 0},
	{"@@Ak", 0}, {"@@AL", 0}, {"@@AD", 0}, {"@@AC", 0},
	//
	// M12 Only
	// 
	{"@@Am", 0}, {"@@AM", 0}, {"@@AQ", 0}, {"@@AS", 0},
	{"@@Bd", 0}, {"@@Bh", 0}, {"@@Bp", 0},
	{"@@Cc", 0}, {"@@Ch", 0}, {"@@Ck", 0}, {"@@Co", 0},
	{"@@Gb", 0}, {"@@Gc", 0}, {"@@Gd", 0}, {"@@Gd", 0},
	{"@@Ge", 0}, {"@@Gf", 0}, {"@@Gj", 0}, {"@@Gk", 0},
	{"@@Ha", 0}, {"@@Hb", 0}, {"@@Hn", 0}, {"@@Hr", 0},
	{"@@Ia", 0}												// 87 Commands 
};
//
// Semaphore related stuff
#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
	// union semun is defined by including <sys/sem.h>
#else
	// According to X/OPEN we have to define it ourselves
	union semun {
		int val;					/* value for SETVAL */
		struct semid_ds *buf;		/* buffer for IPC_STAT, IPC_SET */
		unsigned short *array;		/* array for GETALL, SETALL */
									/* Linux specific part: */
		struct seminfo *__buf;		/* buffer for IPC_INFO */
	};
#endif

//
// Global vars
//
char *Buf;
int fd;
struct stat statbuf;
//
int sock;
struct sockaddr_in soname;
int debug = 0;
int maxconn = 25;
int verbose = 0;
int port = -1;
int forkit=1;
char defport[] = "12321";
char *portl = defport;
char *myname;
//
// function prototypes
//
char *proconf( void );
void sig_chld( int );
int read_data( void );
int parsearg( int, char** );
