Don't log useless things in the main loop
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
23
src/bind.c
23
src/bind.c
@@ -222,9 +222,8 @@ gt_bind(int argc, char **argv)
|
|||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
if (errno == EBADF) {
|
if (errno == EBADF) {
|
||||||
perror("select");
|
perror("select");
|
||||||
return 1;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,28 +314,16 @@ gt_bind(int argc, char **argv)
|
|||||||
struct ip_common ic;
|
struct ip_common ic;
|
||||||
const int r = tun_read(tun_fd, buf, bufsize);
|
const int r = tun_read(tun_fd, buf, bufsize);
|
||||||
|
|
||||||
if (r <= 0) {
|
if (!ip_get_common(&ic, buf, r))
|
||||||
if (r == -1 && errno != EAGAIN)
|
mud_send(mud, buf, r, ic.tc);
|
||||||
perror("tun_read");
|
|
||||||
} else if ((!ip_get_common(&ic, buf, r)) &&
|
|
||||||
(mud_send(mud, buf, r, ic.tc) == -1)) {
|
|
||||||
if (errno != EAGAIN)
|
|
||||||
perror("mud_send");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(mud_fd, &rfds)) {
|
if (FD_ISSET(mud_fd, &rfds)) {
|
||||||
struct ip_common ic;
|
struct ip_common ic;
|
||||||
const int r = mud_recv(mud, buf, bufsize);
|
const int r = mud_recv(mud, buf, bufsize);
|
||||||
|
|
||||||
if (r <= 0) {
|
if (!ip_get_common(&ic, buf, r))
|
||||||
if (r == -1 && errno != EAGAIN)
|
tun_write(tun_fd, buf, r);
|
||||||
perror("mud_recv");
|
|
||||||
} else if ((!ip_get_common(&ic, buf, r)) &&
|
|
||||||
(tun_write(tun_fd, buf, r) == -1)) {
|
|
||||||
if (errno != EAGAIN)
|
|
||||||
perror("tun_write");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
|
|||||||
6
src/ip.h
6
src/ip.h
@@ -13,16 +13,16 @@ ip_get_version(const uint8_t *data)
|
|||||||
return data[0] >> 4;
|
return data[0] >> 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint16_t
|
static inline int
|
||||||
ip_read16(const uint8_t *src)
|
ip_read16(const uint8_t *src)
|
||||||
{
|
{
|
||||||
uint16_t ret = src[1];
|
uint16_t ret = src[1];
|
||||||
ret |= ((uint16_t)src[0]) << 8;
|
ret |= ((uint16_t)src[0]) << 8;
|
||||||
return ret;
|
return (int)ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
ip_get_common(struct ip_common *ic, const uint8_t *data, size_t size)
|
ip_get_common(struct ip_common *ic, const uint8_t *data, int size)
|
||||||
{
|
{
|
||||||
if (size < 20)
|
if (size < 20)
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user