mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2026-03-14 21:10:11 +01:00
handle lan ip change via bash instead of lua
This commit is contained in:
parent
9a7949d957
commit
1641208858
1 changed files with 12 additions and 7 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue