Factor out safe_write() into ncmlib and use it in ndhc as well.
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "packet.h"
|
||||
#include "options.h"
|
||||
#include "log.h"
|
||||
#include "io.h"
|
||||
#include "script.h"
|
||||
|
||||
static int snprintip(char *dest, size_t size, unsigned char *ip)
|
||||
@@ -152,21 +153,10 @@ static int open_ifch(void) {
|
||||
|
||||
static void sockwrite(int fd, const char *buf, size_t count)
|
||||
{
|
||||
int ret;
|
||||
int sent = 0;
|
||||
while (1) {
|
||||
ret = write(fd, buf + sent, count - sent);
|
||||
if (ret == -1) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
log_error("sockwrite: write failed: %s", strerror(errno));
|
||||
break;
|
||||
}
|
||||
sent += ret;
|
||||
if (sent == count)
|
||||
break;
|
||||
}
|
||||
log_line("writing: %s", buf);
|
||||
if (safe_write(fd, buf, count) == -1)
|
||||
log_error("sockwrite: write failed: %s", strerror(errno));
|
||||
else
|
||||
log_line("sent to ifchd: %s", buf);
|
||||
}
|
||||
|
||||
static void deconfig_if(void)
|
||||
|
||||
Reference in New Issue
Block a user