2011-12-06 18:15:09 +00:00
|
|
|
diff -up net-tools-1.60/ifconfig.c.bcast net-tools-1.60/ifconfig.c
|
|
|
|
--- net-tools-1.60/ifconfig.c.bcast 2011-11-21 02:31:57.000000000 +0100
|
|
|
|
+++ net-tools-1.60/ifconfig.c 2011-12-02 16:16:06.793742329 +0100
|
|
|
|
@@ -35,6 +35,7 @@
|
2004-11-04 13:57:44 +00:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
+#include <netinet/ip.h>
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -239,9 +240,12 @@ static void version(void)
|
|
|
|
exit(E_USAGE);
|
2004-11-04 13:57:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-static int set_netmask(int skfd, struct ifreq *ifr, struct sockaddr *sa)
|
|
|
|
+static int set_netmask(int skfd, struct ifreq *ifr, struct sockaddr *sa, int new_bcast)
|
|
|
|
{
|
|
|
|
int err = 0;
|
2011-12-06 18:15:09 +00:00
|
|
|
+ struct sockaddr_in * ip_addr, * netmask, *bcast;
|
2004-11-04 13:57:44 +00:00
|
|
|
+ struct ifreq ifraddr;
|
2011-12-06 18:15:09 +00:00
|
|
|
+ struct ifreq ifrbcast;
|
|
|
|
|
|
|
|
memcpy((char *) &ifr->ifr_netmask, (char *) sa,
|
|
|
|
sizeof(struct sockaddr));
|
|
|
|
@@ -250,6 +254,25 @@ static int set_netmask(int skfd, struct
|
2004-11-04 13:57:44 +00:00
|
|
|
strerror(errno));
|
|
|
|
err = 1;
|
|
|
|
}
|
2011-12-06 18:15:09 +00:00
|
|
|
+
|
|
|
|
+ if (new_bcast) {
|
|
|
|
+ memcpy(&ifraddr,ifr,sizeof(struct ifreq));
|
|
|
|
+ memcpy(&ifrbcast,ifr,sizeof(struct ifreq));
|
|
|
|
+ if (ioctl(skfd, SIOCGIFADDR, &ifraddr) < 0) {
|
|
|
|
+ fprintf(stderr, "SIOCGIFADDR: %s\n", strerror(errno));
|
|
|
|
+ err = 1;
|
|
|
|
+ }
|
|
|
|
+ ip_addr = (struct sockaddr_in *)&ifraddr.ifr_addr;
|
|
|
|
+ netmask = (struct sockaddr_in *)&ifr->ifr_netmask;
|
|
|
|
+ bcast = (struct sockaddr_in *)&ifrbcast.ifr_broadaddr;
|
|
|
|
+ /* calculate new broadcast adress */
|
|
|
|
+ bcast->sin_addr.s_addr = ip_addr->sin_addr.s_addr | ~netmask->sin_addr.s_addr;
|
|
|
|
+ /* set new broadcast adress */
|
|
|
|
+ if (ioctl(skfd, SIOCSIFBRDADDR, &ifrbcast) < 0) {
|
|
|
|
+ fprintf(stderr, "SIOCSIFBROADCAST: %s\n", strerror(errno));
|
|
|
|
+ err = 1;
|
|
|
|
+ }
|
2004-11-04 13:57:44 +00:00
|
|
|
+ }
|
2011-12-06 18:15:09 +00:00
|
|
|
return err;
|
2004-11-04 13:57:44 +00:00
|
|
|
}
|
|
|
|
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -262,7 +285,7 @@ int main(int argc, char **argv)
|
2004-11-04 13:57:44 +00:00
|
|
|
struct aftype *ap;
|
|
|
|
struct hwtype *hw;
|
|
|
|
struct ifreq ifr;
|
2011-12-06 18:15:09 +00:00
|
|
|
- int goterr = 0, didnetmask = 0, neednetmask=0;
|
|
|
|
+ int goterr = 0, didnetmask = 0, neednetmask=0, dobcast = 1;
|
2004-11-04 13:57:44 +00:00
|
|
|
char **spp;
|
|
|
|
int fd;
|
|
|
|
#if HAVE_AFINET6
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -547,6 +570,7 @@ int main(int argc, char **argv)
|
2004-11-04 13:57:44 +00:00
|
|
|
strerror(errno));
|
|
|
|
goterr = 1;
|
|
|
|
}
|
|
|
|
+ dobcast = 0;
|
|
|
|
spp++;
|
|
|
|
}
|
|
|
|
goterr |= set_flag(ifr.ifr_name, IFF_BROADCAST);
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -589,7 +613,7 @@ int main(int argc, char **argv)
|
2004-11-04 13:57:44 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
didnetmask++;
|
2011-12-06 18:15:09 +00:00
|
|
|
- goterr |= set_netmask(ap->fd, &ifr, &sa);
|
|
|
|
+ goterr |= set_netmask(ap->fd, &ifr, &sa, dobcast);
|
2004-11-04 13:57:44 +00:00
|
|
|
spp++;
|
|
|
|
continue;
|
|
|
|
}
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -1045,7 +1069,7 @@ int main(int argc, char **argv)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (neednetmask) {
|
|
|
|
- goterr |= set_netmask(skfd, &ifr, &samask);
|
|
|
|
+ goterr |= set_netmask(skfd, &ifr, &samask, dobcast);
|
|
|
|
didnetmask++;
|
|
|
|
}
|
2004-11-04 13:57:44 +00:00
|
|
|
|