net-tools/net-tools-1.60-bcast.patch

87 lines
2.5 KiB
Diff
Raw Normal View History

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 @@
#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);
}
-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;
+ 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
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;
+ }
+ }
2011-12-06 18:15:09 +00:00
return err;
}
2011-12-06 18:15:09 +00:00
@@ -262,7 +285,7 @@ int main(int argc, char **argv)
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;
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)
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)
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);
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++;
}