Skip to content

Commit

Permalink
Only send data if interface is running
Browse files Browse the repository at this point in the history
If the macnocker client tries to send data, but the interface is not running,
this will result in error messages. However, an interface being down is a
valid state and should not result in error messages. So first check the current
state of the interface before trying to send data.

Fixes: #104
Signed-off-by: Fabian Bläse <fabian@blaese.de>
Acked-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
  • Loading branch information
fblaese committed Apr 22, 2020
1 parent ffd1a64 commit ce01c32
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions macnockclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ void macNockClient_run()
{
log_trace("[c] sending\n");

// check if bound interface is down, trying to send data would result in an error
if (!(ioctl(fd, SIOCGIFFLAGS, &ifr) == 0))
{
perror("[c] ERROR: Can't read Interface information");
goto retry;
}
if (!(ifr.ifr_flags & IFF_RUNNING))
{
// interface is not running, silently ignore
log_debug("[c] interface is not running\n");
goto retry;
}

int sent = sendto(fd, nock, len, 0, (struct sockaddr *)&servaddr, sizeof(servaddr));
if (sent == -1)
{
Expand All @@ -96,6 +109,7 @@ void macNockClient_run()
perror("[c] ERROR: Can't send all data");
}

retry:
usleep(1 * 1000 * 1000); // sleep 1 s
}

Expand Down

0 comments on commit ce01c32

Please sign in to comment.