Ejemplo n.º 1
0
int
main_poll_server(int argc, char *const *argv)
{
	int ch;
	int npeer = 0;
	char *p;
	struct ntp_peerset *npl;
	struct ntp_peer *mon = NULL;
	struct ntp_peer *np;
	struct todolist *tdl;
	double duration = 1800;

	setbuf(stdout, NULL);
	setbuf(stderr, NULL);

	ArgTracefile("-");

	tdl = TODO_NewList();
	Time_Unix_Passive();

	npl = NTP_PeerSet_New(NULL);
	AN(npl);

	while ((ch = getopt(argc, argv, "d:m:t:")) != -1) {
		switch(ch) {
		case 'd':
			duration = strtod(optarg, &p);
			if (*p != '\0' || duration < 1.0)
				Fail(NULL, 0, "Invalid -d argument");
			break;
		case 'm':
			mon = NTP_Peer_NewLookup(NULL, optarg);
			if (mon == NULL)
				Fail(NULL, 0, "Monitor (-m) didn't resolve.");
			break;
		case 't':
			ArgTracefile(optarg);
			break;
		default:
			Fail(NULL, 0,
			    "Usage %s [-d duration] [-m monitor] "
			    "[-t tracefile] server...", argv[0]);
			break;
		}
	}
	argc -= optind;
	argv += optind;

	for (ch = 0; ch < argc; ch++)
		npeer += NTP_PeerSet_Add(NULL, npl, argv[ch]);
	Put(NULL, OCX_TRACE, "# NTIMED Format poll-server 1.0\n");
	Put(NULL, OCX_TRACE, "# Found %d peers\n", npeer);
	if (npeer == 0)
		Fail(NULL, 0, "No peers found");

	NTP_PeerSet_Foreach(np, npl) {
		Put(NULL, OCX_TRACE, "# Peer %s %s\n", np->hostname, np->ip);
		np->filter_func = mps_filter;
	}
Ejemplo n.º 2
0
int
main_client(int argc, char *const *argv)
{
	int ch;
	struct ntp_peer *np;
	struct ntp_peerset *npl;
	struct todolist *tdl;
	struct combine_delta *cd;
	int fd;
	int npeer = 0;

	setbuf(stdout, NULL);
	setbuf(stderr, NULL);

	tdl = TODO_NewList();
	Time_Unix(tdl);

	PLL_Init();

	npl = NTP_PeerSet_New(NULL);

	Param_Register(client_param_table);
	NF_Init();

	while ((ch = getopt(argc, argv, "p:t:")) != -1) {
		switch(ch) {
		case 'p':
			Param_Tweak(NULL, optarg);
			break;
		case 't':
			ArgTracefile(optarg);
			break;
		default:
			Fail(NULL, 0,
			    "Usage %s [-p param] [-t tracefile] servers...",
			    argv[0]);
			break;
		}
	}
	argc -= optind;
	argv += optind;

	for (ch = 0; ch < argc; ch++)
		npeer += NTP_PeerSet_Add(NULL, npl, argv[ch]);
	if (npeer == 0)
		Fail(NULL, 0, "No NTP peers found");

	Put(NULL, OCX_TRACE, "# NTIMED Format client 1.0\n");
	Put(NULL, OCX_TRACE, "# Found %d peers\n", npeer);

	Param_Report(NULL, OCX_TRACE);

#ifndef NOIPV6
	/* Attempt IPv6, fall back to IPv4 */
	fd = UdpTimedSocket(NULL, AF_INET6);
	if (fd < 0)
		fd = UdpTimedSocket(NULL, AF_INET);
#else
	fd = UdpTimedSocket(NULL, AF_INET);
#endif
	if (fd < 0)
		Fail(NULL, errno, "Could not open UDP socket");

	cd = CD_New();

	NTP_PeerSet_Foreach(np, npl) {
		NF_New(np);
		np->combiner = CD_AddSource(cd, np->hostname, np->ip);
	}