Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/ntp/ntpd/ntp_signd.c
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
static int | static int | ||||
write_all(int fd, const void *buf, size_t len) | write_all(int fd, const void *buf, size_t len) | ||||
{ | { | ||||
size_t total = 0; | size_t total = 0; | ||||
while (len) { | while (len) { | ||||
int n = write(fd, buf, len); | int n = write(fd, buf, len); | ||||
if (n <= 0) return total; | if (n <= 0) return total; | ||||
buf = n + (char *)buf; | buf = n + (const char *)buf; | ||||
len -= n; | len -= n; | ||||
total += n; | total += n; | ||||
} | } | ||||
return total; | return total; | ||||
} | } | ||||
/* | /* | ||||
keep reading until its all read | keep reading until its all read | ||||
Show All 27 Lines | |||||
/* | /* | ||||
receive a packet in length prefix format | receive a packet in length prefix format | ||||
*/ | */ | ||||
static int | static int | ||||
recv_packet(int fd, char **buf, uint32_t *len) | recv_packet(int fd, char **buf, uint32_t *len) | ||||
{ | { | ||||
if (read_all(fd, len, sizeof(*len)) != sizeof(*len)) return -1; | if (read_all(fd, len, sizeof(*len)) != sizeof(*len)) return -1; | ||||
*len = ntohl(*len); | *len = ntohl(*len); | ||||
(*buf) = emalloc(*len); | *buf = emalloc(*len); | ||||
if (read_all(fd, *buf, *len) != *len) { | if (read_all(fd, *buf, *len) != *len) { | ||||
free(*buf); | free(*buf); | ||||
*buf = NULL; | |||||
return -1; | return -1; | ||||
} | } | ||||
return 0; | return 0; | ||||
} | } | ||||
void | void | ||||
send_via_ntp_signd( | send_via_ntp_signd( | ||||
struct recvbuf *rbufp, /* receive packet pointer */ | struct recvbuf *rbufp, /* receive packet pointer */ | ||||
▲ Show 20 Lines • Show All 116 Lines • Show Last 20 Lines |