refclock_mx4200.c (302408) | refclock_mx4200.c (316068) |
---|---|
1/* 2 * This software was developed by the Computer Systems Engineering group 3 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66. 4 * 5 * Copyright (c) 1992 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 1582 unchanged lines hidden (view full) --- 1591 struct peer *peer; 1592 char *fmt; 1593 va_dcl 1594#endif /* __STDC__ */ 1595{ 1596 struct refclockproc *pp; 1597 struct mx4200unit *up; 1598 | 1/* 2 * This software was developed by the Computer Systems Engineering group 3 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66. 4 * 5 * Copyright (c) 1992 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 1582 unchanged lines hidden (view full) --- 1591 struct peer *peer; 1592 char *fmt; 1593 va_dcl 1594#endif /* __STDC__ */ 1595{ 1596 struct refclockproc *pp; 1597 struct mx4200unit *up; 1598 |
1599 register char *cp; | 1599 register char *cp, *ep; |
1600 register int n, m; 1601 va_list ap; 1602 char buf[1024]; 1603 u_char ck; 1604 | 1600 register int n, m; 1601 va_list ap; 1602 char buf[1024]; 1603 u_char ck; 1604 |
1605 pp = peer->procptr; 1606 up = pp->unitptr; 1607 1608 cp = buf; 1609 ep = cp + sizeof(buf); 1610 *cp++ = '$'; 1611 |
|
1605#if defined(__STDC__) 1606 va_start(ap, fmt); 1607#else 1608 va_start(ap); 1609#endif /* __STDC__ */ | 1612#if defined(__STDC__) 1613 va_start(ap, fmt); 1614#else 1615 va_start(ap); 1616#endif /* __STDC__ */ |
1617 n = VSNPRINTF((cp, (size_t)(ep - cp), fmt, ap)); 1618 va_end(ap); 1619 if (n < 0 || (size_t)n >= (size_t)(ep - cp)) 1620 goto overflow; |
|
1610 | 1621 |
1611 pp = peer->procptr; 1612 up = pp->unitptr; 1613 1614 cp = buf; 1615 *cp++ = '$'; 1616 n = VSNPRINTF((cp, sizeof(buf) - 1, fmt, ap)); | |
1617 ck = mx4200_cksum(cp, n); | 1622 ck = mx4200_cksum(cp, n); |
1623 cp += n; 1624 n = SNPRINTF((cp, (size_t)(ep - cp), "*%02X\r\n", ck)); 1625 if (n < 0 || (size_t)n >= (size_t)(ep - cp)) 1626 goto overflow; |
|
1618 cp += n; | 1627 cp += n; |
1619 ++n; 1620 n += SNPRINTF((cp, sizeof(buf) - n - 5, "*%02X\r\n", ck)); 1621 1622 m = write(pp->io.fd, buf, (unsigned)n); | 1628 m = write(pp->io.fd, buf, (unsigned)(cp - buf)); |
1623 if (m < 0) 1624 msyslog(LOG_ERR, "mx4200_send: write: %m (%s)", buf); 1625 mx4200_debug(peer, "mx4200_send: %d %s\n", m, buf); | 1629 if (m < 0) 1630 msyslog(LOG_ERR, "mx4200_send: write: %m (%s)", buf); 1631 mx4200_debug(peer, "mx4200_send: %d %s\n", m, buf); |
1626 va_end(ap); | 1632 1633 overflow: 1634 msyslog(LOG_ERR, "mx4200_send: %s", "data exceeds buffer size"); |
1627} 1628 1629#else 1630int refclock_mx4200_bs; 1631#endif /* REFCLOCK */ | 1635} 1636 1637#else 1638int refclock_mx4200_bs; 1639#endif /* REFCLOCK */ |