Skip to content

Commit

Permalink
Merge pull request #35 from andrewvoznytsa/master
Browse files Browse the repository at this point in the history
Fix small logger issues
  • Loading branch information
chipot committed Dec 22, 2020
2 parents 896148e + 1142d5d commit d2708eb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion private.h
Expand Up @@ -105,7 +105,7 @@ struct device {
# endif

/* Internal log facilities */
t_tuntap_log tuntap_log;
extern t_tuntap_log tuntap_log;
void tuntap_log_default(int, const char *);
void tuntap_log_hexdump(void *, size_t);
void tuntap_log_chksum(void *, int);
Expand Down
5 changes: 4 additions & 1 deletion tuntap-unix.c
Expand Up @@ -34,6 +34,7 @@
# include <netinet/if_ether.h>
#endif

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -268,7 +269,9 @@ tuntap_read(struct device *dev, void *buf, size_t size) {

n = read(dev->tun_fd, buf, size);
if (n == -1) {
tuntap_log(TUNTAP_LOG_WARN, "Can't to read from device");
if (errno != EAGAIN) {
tuntap_log(TUNTAP_LOG_WARN, "Can't to read from device");
}
return -1;
}
return n;
Expand Down
6 changes: 4 additions & 2 deletions tuntap_log.c
Expand Up @@ -26,6 +26,8 @@
#include "tuntap.h"
#include "private.h"

t_tuntap_log tuntap_log = NULL;

void
tuntap_log_set_cb(t_tuntap_log cb) {
if (cb == NULL)
Expand Down Expand Up @@ -79,8 +81,8 @@ tuntap_log_hexdump(void *data, size_t size) {
for (n = 1; n <= size; n++) {
if (n % 16 == 1) {
/* store address for this line */
snprintf(addrstr, sizeof(addrstr), "%.4llx",
((uintptr_t)p - (uintptr_t)data) );
snprintf(addrstr, sizeof(addrstr), "%.4zx",
(p - (unsigned char *)data) );
}

c = *p;
Expand Down

0 comments on commit d2708eb

Please sign in to comment.