Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove dependency on libbsd #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ AC_CHECK_LIB([util], [malloc])
AC_CHECK_HEADERS([arpa/inet.h fcntl.h float.h limits.h netdb.h \
netinet/in.h stdlib.h string.h sys/param.h sys/socket.h \
sys/time.h unistd.h util.h])
AC_CHECK_HEADERS([bsd/stdlib.h], [], \
[echo "ERROR: previous header not found."; exit -1])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
Expand All @@ -51,7 +49,7 @@ AC_STRUCT_TM
AC_FUNC_MALLOC
AC_FUNC_SELECT_ARGTYPES
AC_FUNC_STRFTIME
AC_CHECK_FUNCS([gettimeofday memset select socket])
AC_CHECK_FUNCS([arc4random gettimeofday memset select socket])

# Check for uname prog
AC_PATH_PROG([UNAME], [uname],
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bin_PROGRAMS = rdate

rdate_SOURCES = rdate.c

rdate_LDADD = librdate.a -lbsd
rdate_LDADD = librdate.a

noinst_LIBRARIES = librdate.a

Expand Down
23 changes: 14 additions & 9 deletions src/ntp.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
#include <unistd.h>

#include "ntpleaps.h"
#include <bsd/stdlib.h>

/*
* NTP definitions. Note that these assume 8-bit bytes - sigh. There
Expand Down Expand Up @@ -101,10 +100,10 @@
#define MILLION_D 1.0e6 /* Must be equal to MILLION_L */

struct ntp_data {
u_char status;
u_char version;
u_char mode;
u_char stratum;
uint8_t status;
uint8_t version;
uint8_t mode;
uint8_t stratum;
double receive;
double transmit;
double current;
Expand All @@ -119,7 +118,7 @@ void ntp_client(const char *, int, struct timeval *, struct timeval *, int, int,
int sync_ntp(int, const struct sockaddr *, socklen_t, double *, double *, int);
int write_packet(int, struct ntp_data *);
int read_packet(int, struct ntp_data *, double *, double *);
void unpack_ntp(struct ntp_data *, u_char *);
void unpack_ntp(struct ntp_data *, uint8_t *);
double current_time(double);
void create_timeval(double, struct timeval *, struct timeval *);

Expand Down Expand Up @@ -277,14 +276,20 @@ sync_ntp(int fd, const struct sockaddr *peer, socklen_t addrlen,
int
write_packet(int fd, struct ntp_data *data)
{
u_char packet[NTP_PACKET_MIN];
uint8_t packet[NTP_PACKET_MIN];
ssize_t length;

memset(packet, 0, sizeof(packet));

packet[0] = (NTP_VERSION << 3) | (NTP_MODE_CLIENT);

#ifndef HAVE_ARC4RANDOM
uint64_t tmp;
getentropy(&tmp, 8);
data->xmitck = tmp;
#else
data->xmitck = (uint64_t)arc4random() << 32 | arc4random();
#endif

/*
* Send out a random 64-bit number as our transmit time. The NTP
Expand Down Expand Up @@ -325,7 +330,7 @@ write_packet(int fd, struct ntp_data *data)
int
read_packet(int fd, struct ntp_data *data, double *off, double *error)
{
u_char receive[NTP_PACKET_MAX];
uint8_t receive[NTP_PACKET_MAX];
struct timeval tv;
double x, y;
int length, r;
Expand Down Expand Up @@ -421,7 +426,7 @@ read_packet(int fd, struct ntp_data *data, double *off, double *error)
* to SNTP.
*/
void
unpack_ntp(struct ntp_data *data, u_char *packet)
unpack_ntp(struct ntp_data *data, uint8_t *packet)
{
int i;
double d;
Expand Down