Browse code

- tm free lumps fix, thanks to Richard Fogel <rfogel@borderware.com>

Andrei Pelinescu-Onciul authored on 01/07/2004 15:33:58
Showing 2 changed files
... ...
@@ -60,10 +60,12 @@
60 60
 */
61 61
 inline static void free_via_clen_lump( struct lump **list )
62 62
 {
63
-	struct lump *prev_lump, *lump, *a, *foo;
63
+	struct lump *prev_lump, *lump, *a, *foo, *next;
64 64
 
65
+	next=0;
65 66
 	prev_lump=0;
66
-	for(lump=*list;lump;lump=lump->next) {
67
+	for(lump=*list;lump;lump=next) {
68
+		next=lump->next;
67 69
 		if (lump->type==HDR_VIA||lump->type==HDR_CONTENTLENGTH) {
68 70
 			a=lump->before;
69 71
 			while(a) {
... ...
@@ -51,6 +51,8 @@
51 51
 #include <errno.h>
52 52
 
53 53
 #define FLAGS 1
54
+#define IF_DOWN 2
55
+#define IF_UP   4
54 56
 
55 57
 
56 58
 static char* version="ifls 0.1";
... ...
@@ -63,6 +65,8 @@ Options:\n\
63 65
     -4      list only ipv4 interfaces\n\
64 66
     -6      list only ipv6 interfaces\n\
65 67
     -f      show also the interface flags\n\
68
+    -U      brings all the matching interfaces up\n\
69
+    -D      brings all the matching interfaces down\n\
66 70
     -V      version number\n\
67 71
     -h      this help message\n\
68 72
 ";
... ...
@@ -136,7 +140,7 @@ int ls_ifflags(char* name, int family , int options)
136 140
 		/*goto error;*/
137 141
 	}
138 142
 #endif
139
-	if (options & FLAGS){
143
+	if (options & (FLAGS|IF_DOWN|IF_UP)){
140 144
 		if (ioctl(s, SIOCGIFFLAGS, &ifr)==-1){
141 145
 			fprintf(stderr, "ls_if: flags ioctl for %s  failed: %s\n",
142 146
 					name, strerror(errno));
... ...
@@ -159,7 +163,21 @@ int ls_ifflags(char* name, int family , int options)
159 163
 		/*if (ifr.ifr_flags & IFF_AUTOMEDIA) printf ("AUTOMEDIA ");*/
160 164
 		/*if (ifr.ifr_flags & IFF_DYNAMIC ) printf ("DYNAMIC ");*/
161 165
 		printf ("\n");
166
+		if (options & IF_DOWN){
167
+			ifr.ifr_flags &= ~IFF_UP;
168
+		}
169
+		if (options & IF_UP){
170
+			ifr.ifr_flags |= IFF_UP;
171
+		}
172
+		if (options & (IF_UP|IF_DOWN)){
173
+			if (ioctl(s, SIOCSIFFLAGS, &ifr)==-1){
174
+				fprintf(stderr, "ls_if: set flags ioctl for %s  failed: %s\n",
175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178
+		}
162 179
 	};
180
+		
163 181
 	close(s);
164 182
 	return 0;
165 183
 error:
... ...
@@ -262,7 +280,7 @@ int main(int argc, char**argv)
262 280
 	name=0;
263 281
 	no=0;
264 282
 	opterr=0;
265
-	while((c=getopt(argc, argv, "a46fhV"))!=-1){
283
+	while((c=getopt(argc, argv, "a46fhVUD"))!=-1){
266 284
 		switch(c){
267 285
 			case 'a':
268 286
 				ipv6=ipv4=1;
... ...
@@ -283,6 +301,12 @@ int main(int argc, char**argv)
283 301
 				printf("%s\n", id);
284 302
 				exit(0);
285 303
 				break;
304
+			case 'D':
305
+				options|=IF_DOWN;
306
+				break;
307
+			case 'U':
308
+				options|=IF_UP;
309
+				break;
286 310
 			case 'h':
287 311
 				printf("version: %s\n", version);
288 312
 				printf("%s", help_msg);