summaryrefslogtreecommitdiff
path: root/recipes/net-tools/files/net-tools-1.60-bcast.patch
blob: 9489e26352269b388e3f80818aa9216c22cc491d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
--- net-tools-1.60/ifconfig.c.broadcast	2004-11-03 12:05:30.000000000 +0100
+++ net-tools-1.60/ifconfig.c	2004-11-04 15:39:32.817077232 +0100
@@ -36,6 +36,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>
@@ -138,6 +139,7 @@
 	perror("SIOCSIFFLAGS");
 	return -1;
     }
+    
     return (0);
 }
 
@@ -212,17 +214,41 @@
     exit(0);
 }
 
-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;
-
-    memcpy((char *) &ifr->ifr_netmask, (char *) sa,
-	   sizeof(struct sockaddr));
+	struct sockaddr_in * ip_addr, * netmask, *bcast;
+    struct ifreq ifraddr;
+	struct ifreq ifrbcast;
+		
+	memcpy((char *) &ifr->ifr_netmask, (char *) sa,
+	   sizeof(struct sockaddr)); 
     if (ioctl(skfd, SIOCSIFNETMASK, ifr) < 0) {
 	fprintf(stderr, "SIOCSIFNETMASK: %s\n",
 		strerror(errno));
 	err = 1;
     }
+	
+	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;
+    	}
+    }
     return 0;
 }
 
@@ -234,7 +260,7 @@
     struct aftype *ap;
     struct hwtype *hw;
     struct ifreq ifr;
-    int goterr = 0, didnetmask = 0, donetmask = 0;
+    int goterr = 0, didnetmask = 0, donetmask = 0, dobcast = 1;
     char **spp;
     int fd;
 #if HAVE_AFINET6
@@ -506,6 +532,7 @@
 			    strerror(errno));
 		    goterr = 1;
 		}
+		dobcast = 0;
 		spp++;
 	    }
 	    goterr |= set_flag(ifr.ifr_name, IFF_BROADCAST);
@@ -542,7 +569,7 @@
 		continue;
 	    }
 	    didnetmask++;
-	    goterr = set_netmask(ap->fd, &ifr, &sa);
+	    goterr = set_netmask(ap->fd, &ifr, &sa, dobcast);
 	    spp++;
 	    continue;
 	}
@@ -964,7 +991,7 @@
 	/* set CIDR netmask */
 	if (donetmask) {
 		donetmask = 0;
-		goterr = set_netmask(skfd, &ifr, &sa_netmask);
+		goterr = set_netmask(skfd, &ifr, &sa_netmask, dobcast);
 		didnetmask++;
 	}