Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZSYS_INTERFACE variable can be a single digit #1602

Merged
merged 1 commit into from
Jan 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/zbeacon.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,32 @@ s_self_prepare_udp (self_t *self)
send_to = INADDR_BROADCAST;
found_iface = 1;
}
// if ZSYS_INTERFACE is a single digit, use the corresponding interface in
// the interface list
else if (strlen(iface) == 1 && iface[0] >= '0' && iface[0] <= '9')
{
int if_number = atoi(iface);
ziflist_t *iflist = ziflist_new();
assert(iflist);
const char *name = ziflist_first(iflist);
int idx = -1;
while (name) {
idx++;
if (idx==if_number) {
// Using inet_addr instead of inet_aton or inet_atop
// because these are not supported in Win XP
send_to = inet_addr(ziflist_broadcast(iflist));
bind_to = inet_addr(ziflist_address(iflist));
if (self->verbose)
zsys_info("zbeacon: interface=%s address=%s broadcast=%s",
name, ziflist_address(iflist), ziflist_broadcast(iflist));
found_iface = 1;
break; // iface is known, so allow it
}
name = ziflist_next(iflist);
}
ziflist_destroy(&iflist);
}
else {
// Look for matching interface, or first ziflist item
ziflist_t *iflist = ziflist_new ();
Expand Down