6 * Main code for "iwredir". This is a hack to match multiple version
7 * of the tools with multiple kernels on the same system...
9 * This file is released under the GPL license.
10 * Copyright (c) 2003 Jean Tourrilhes <jt@hpl.hp.com>
13 /***************************** INCLUDES *****************************/
15 #include "iwlib.h" /* Header */
17 /*********************** VERSION SUBROUTINES ***********************/
19 /*------------------------------------------------------------------*/
21 * Extract WE version number from /proc/net/wireless
22 * If we have WE-16 and later, the WE version is available at the
23 * end of the header line of the file.
24 * For version prior to that, we can only detect the change from
25 * v11 to v12, so we do an approximate job. Fortunately, v12 to v15
26 * are highly binary compatible (on the struct level).
29 iw_get_kernel_we_version(void)
36 /* Check if /proc/net/wireless is available */
37 fh = fopen(PROC_NET_WIRELESS, "r");
41 fprintf(stderr, "Cannot read " PROC_NET_WIRELESS "\n");
45 /* Read the first line of buffer */
46 fgets(buff, sizeof(buff), fh);
48 if(strstr(buff, "| WE") == NULL)
50 /* Prior to WE16, so explicit version not present */
53 if(strstr(buff, "| Missed") == NULL)
61 /* Read the second line of buffer */
62 fgets(buff, sizeof(buff), fh);
64 /* Get to the last separator, to get the version */
65 p = strrchr(buff, '|');
66 if((p == NULL) || (sscanf(p + 1, "%d", &v) != 1))
68 fprintf(stderr, "Cannot parse " PROC_NET_WIRELESS "\n");
77 /******************************* MAIN ********************************/
79 /*------------------------------------------------------------------*/
92 /* Get current version */
93 version = iw_get_kernel_we_version();
95 version = 15; /* We can only read only WE16 and higher */
97 /* Special case for Wireless Extension Version... */
98 /* This is mostly used in the Makefile, we use an "unlikely" option
99 * to maximise transparency to the tool we masquerade - Jean II */
100 if((argc > 1) && !strcmp(argv[1], "-wev"))
102 printf("%d\n", version);
106 /* Mangle the command name */
107 flen = strlen(argv[0]);
108 if((flen + 3) >= 512)
110 fprintf(stderr, "Command name too long [%s]\n", argv[0]);
113 memcpy(file, argv[0], flen + 1);
114 sprintf(file + flen, "%d", version);
116 /* Execute (won't return) */
117 goterr = execvp(file, argv);
119 /* In case of error */
120 fprintf(stderr, "Can't execute command %s: %s\n", file, strerror(errno));