handle lan ip change via bash instead of lua

This commit is contained in:
Sukru Senli 2015-06-23 11:25:32 +02:00
parent 9a7949d957
commit 1641208858

View file

@ -135,7 +135,10 @@ match_host_to_network(struct uci_section *s, char *netname, char *hostaddr, unsi
is_lan = uci_lookup_option_string(uci_ctx, s, "is_lan");
ifname = uci_lookup_option_string(uci_ctx, s, "ifname");
if (is_lan && !strcmp(is_lan, "1") && strcmp(ifname, "lo")) {
if (is_lan && !strcmp(is_lan, "1")) {
if (ifname && !strcmp(ifname, "lo"))
return;
type = uci_lookup_option_string(uci_ctx, s, "type");
ipaddr = uci_lookup_option_string(uci_ctx, s, "ipaddr");
@ -151,7 +154,7 @@ match_host_to_network(struct uci_section *s, char *netname, char *hostaddr, unsi
if((snet.s_addr ^ rslt.s_addr) == 0) {
*local = 1;
if (type && !strcmp(type, "bridge")) {
sprintf(devbuf, "br-%s", netname);
snprintf(devbuf, 16, "br-%s", netname);
ifname = strdup(devbuf);
}
*dev = ifname;
@ -359,7 +362,8 @@ stats:
static void
arpscan(char *netname, char *ipaddr, char *netmask, char *device, long timeout)
{
struct in_addr ip, nmask, fmask, rmask, last, host;
struct in_addr ip, nmask, fmask, rmask, host;
uint32_t last, addr;
char str[INET_ADDRSTRLEN];
inet_pton(AF_INET, ipaddr, &(ip.s_addr));
@ -367,10 +371,11 @@ arpscan(char *netname, char *ipaddr, char *netmask, char *device, long timeout)
inet_pton(AF_INET, "255.255.255.255", &(fmask.s_addr));
rmask.s_addr = (nmask.s_addr ^ fmask.s_addr);
last.s_addr = (ip.s_addr | rmask.s_addr);
last = ntohl(ip.s_addr | rmask.s_addr);
fprintf(stdout, "Scanning network '%s'\n", netname);
for(host.s_addr = ip.s_addr; host.s_addr <= last.s_addr; host.s_addr++) {
for(addr = ntohl(ip.s_addr); addr <= last; addr++) {
host.s_addr = htonl(addr);
inet_ntop(AF_INET, &(host.s_addr), str, INET_ADDRSTRLEN);
if(arping(str, device, timeout))
fprintf(stdout, "Host found: %s\n", str);
@ -553,9 +558,9 @@ int main(int argc, char **argv)
if (qinf == 1 && qhost == 1)
usage();
else if (qinf == 1 & (qaddr + qmask + qclnt + qport + qscan) == 1)
else if (qinf == 1 && (qaddr + qmask + qclnt + qport + qscan) == 1)
handle_network(interface, qaddr, qmask, qclnt, qport, qscan, timeout);
else if (qhost == 1 & (qnet + qlocal + qdev + qstat) == 1)
else if (qhost == 1 && (qnet + qlocal + qdev + qstat) == 1)
handle_ip(host, qnet, qlocal, qdev, qstat);
else
usage();