FreeBSD/contrib/ntp/ntpd/refclock_ripencc.c
/*
 * ripencc_send - send message to clock
 * use the structures being created by the trimble functions!
 * makes the code more readable/clean
 */
send message to clock
use the structures being created by the trimble functions.
makes the code more readable/clean
send message to clock use the structures being created by the trimble functions . makes the code more readable / clean
static void
ripencc_send(struct peer *peer, TSIPPKT spt)
{
	unsigned char *ip, *op;
	unsigned char obuf[512];
#ifdef DEBUG_RAW
	{
		register struct ripencc_unit *up;
		register struct refclockproc *pp;	
		pp = peer->procptr;
		up = pp->unitptr;
		if (debug)
			printf("ripencc_send(%d, %02X)\n", up->unit, cmd);
	}
#endif 
	ip = spt.buf;
	op = obuf;
	*op++ = 0x10;
	*op++ = spt.code;
	while (spt.len--) {
		if (op-obuf > sizeof(obuf)-5) {
			msyslog(LOG_ERR, "ripencc_send obuf overflow!");
			refclock_report(peer, CEVNT_FAULT);
			return;
		}
		if (*ip == 0x10) 
			*op++ = 0x10;
		*op++ = *ip++;
	}
	*op++ = 0x10;
	*op++ = 0x03;
#ifdef DEBUG_RAW
	if (debug) { 
		unsigned char *cp;
		int i;
		printf("ripencc_send: len %d\n", op-obuf);
		for (i=1, cp=obuf; cp<op; i++, cp++) {
			printf(" %02X", *cp);
			if (i%10 == 0) 
				printf("\n");
		}
		printf("\n");
	}
#endif 
	if (write(peer->procptr->io.fd, obuf, op-obuf) == -1) {
		refclock_report(peer, CEVNT_FAULT);
	}
}
static void ripencc_send ( struct peer * peer , TSIPPKT spt ) { unsigned char * ip , * op ; unsigned char obuf [ 512 ] ; #ifdef DEBUG_RAW { register struct ripencc_unit * up ; register struct refclockproc * pp ; pp = peer -> procptr ; up = pp -> unitptr ; if ( debug ) printf ( " \n " , up -> unit , cmd ) ; } #endif ip = spt . buf ; op = obuf ; * op ++ = 0x10 ; * op ++ = spt . code ; while ( spt . len -- ) { if ( op - obuf > sizeof ( obuf ) - 5 ) { msyslog ( LOG_ERR , " " ) ; refclock_report ( peer , CEVNT_FAULT ) ; return ; } if ( * ip == 0x10 ) * op ++ = 0x10 ; * op ++ = * ip ++ ; } * op ++ = 0x10 ; * op ++ = 0x03 ; #ifdef DEBUG_RAW if ( debug ) { unsigned char * cp ; int i ; printf ( " \n " , op - obuf ) ; for ( i = 1 , cp = obuf ; cp < op ; i ++ , cp ++ ) { printf ( " " , * cp ) ; if ( i % 10 == 0 ) printf ( " \n " ) ; } printf ( " \n " ) ; } #endif if ( write ( peer -> procptr -> io . fd , obuf , op - obuf ) == -1 ) { refclock_report ( peer , CEVNT_FAULT ) ; } }
ripencc_send - send message to clock
 use the structures being created by the trimble functions!
ripencc_send - send message to clock use the structures being created by the trimble functions!
/* DEBUG_RAW */ /* byte stuffing */ /* print raw packet */ /* DEBUG_RAW */