Factor out safe_write() into ncmlib and use it in ndhc as well.

This commit is contained in:
Nicholas J. Kain
2010-11-13 08:18:23 -05:00
parent edf3b02b6a
commit a43e69c7ae
6 changed files with 102 additions and 48 deletions

View File

@ -10,6 +10,7 @@
#include "packet.h"
#include "log.h"
#include "io.h"
#include "dhcpd.h"
#include "options.h"
@ -199,20 +200,9 @@ int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip,
if (connect(fd, (struct sockaddr *)&client, sizeof(struct sockaddr)) == -1)
goto out_fd;
int remain = sizeof(struct dhcpMessage);
int sent = 0;
while (1) {
result = write(fd, ((char *)payload) + sent, remain - sent);
if (result == -1) {
if (errno == EINTR)
continue;
log_error("kernel_packet: write failed: %s", strerror(errno));
break;
}
sent += result;
if (remain == sent)
break;
}
result = safe_write(fd, (const char *)payload, sizeof(struct dhcpMessage));
if (result == -1)
log_error("kernel_packet: write failed: %s", strerror(errno));
out_fd:
close(fd);
out: