]> git.decadent.org.uk Git - ap-utils.git/blob - src/bridge.c
Imported Upstream version 1.5~pre2
[ap-utils.git] / src / bridge.c
1 /*
2  *      bridge.c from Access Point SNMP Utils for Linux
3  *
4  * Copyright (c) 2002 Roman Festchook <roma at polesye dot net>
5  * Copyright (c) 2005 Jan Rafaj <jr-aputils at cedric dot unob dot cz>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License Version 2 from
9  * June 1991 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21
22 #include <stdlib.h>
23 #include <string.h>
24 #include <sys/types.h>
25 #include "ap-utils.h"
26
27 #define IPADDR _("[I] IP: ")
28 #define NETMASK _("[N] Netmask: ")
29 #define GATEWAY _("[G] Gateway: ")
30 #define IP_FILTER _("[F] Filter non-IP traffic: ")
31 #define PR_PORT _("[P] Primary port: ")
32 #define SB_ATTMAC _("Attached station MAC: ")
33 #define DHCP _("[D] DHCP client: ")
34 #define OPER _("[O] Operational mode: ")
35 #define REMOTE_MAC _("[M] Preferred BSSID (remote MAC addr.): ")
36 #define CF_PORT _("[C] Configuration-enabled port(s): ")
37 #define TRAP_PORT _("[T] Trap-sending port: ")
38 #define FW_BCAST _("[R] Forward broadcast traffic: ")
39 #define SB_BCAST _("[B] Isolate wireless clients (broadcast traffic): ")
40 #define SB_UCAST _("[U] Isolate wireless clients (unicast traffic): ")
41 #define HELP _("INGFPDOMSCRBUT - set; W - write conf; Q - quit to menu")
42
43 extern short ap_type, ap_vendorext;
44
45
46 void bridging()
47 {
48     char sysTrapSwitch[] = {
49         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x01, 0x03, 0x00
50     };
51
52     char operIPAddress[] = {
53         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x01, 0x00
54     };
55     char operIPMask[] = {
56         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x02, 0x00
57     };
58     char operEthernetAddress[] = {
59         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x03, 0x00
60     };
61     char operGateway[] = {
62         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x04, 0x00
63     };
64     char operDHCP[] = {
65         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x05, 0x00
66     };
67     char operPrimaryPort[] = {
68         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x06, 0x00
69     };
70
71     /* This one is ATMEL410 SBRIDGES MIB and ATMEL12350 all MIBs specific. */
72     char operConfigurationPort[] = {
73         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x02, 0x07, 0x00
74     };
75
76     /* This one is ATMEL12350 GEMTEK MIB and ATMEL12350 EZYNET MIB specific. */
77     char operTrapPort[] = {
78         0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x01, 0x02, 0x08, 0x00
79     };
80
81     char operIPFilter[] = {
82         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x01, 0x00
83     };
84
85 char *bridge_modes[6] = {
86     _("Wireless Bridge Point to MultiPoint"),
87     _("Access Point"),
88     _("Access Point client"),
89     _("Wireless Bridge Point to Point"),
90     _("Repeater"),
91     _("unknown")
92 };
93
94     /* These 3 are ATMEL410 SBRIDGES MIB and ATMEL12350 all MIBs specific. */
95     char operForwarbBcast[] = {
96         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x02, 0x00
97     };
98     char operSendBackBcast[] = {
99         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x03, 0x00
100     };
101     char operSendBackUnicast[] = {
102         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x03, 0x04, 0x00
103     };
104
105     char bridgeOperationalMode[] = {
106         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x01, 0x00
107     };
108     char bridgeRemoteBridgeBSSID[] = {
109         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x02, 0x00
110     };
111
112     extern WINDOW *main_sub;
113     varbind varbinds[15];
114     struct in_addr ip, mask, gw;
115     unsigned char message[1024], filter, primary_port, dhcp, RemoteBSSID[6],
116         bridge_mode, traps, config_port, fw_bcast, sb_bcast,
117         sb_ucast;
118     char m_filter = 0, m_bridge_mode = 0, m_primary_port = 0, m_traps = 0,
119         m_dhcp = 0, m_ip = 0, m_mask = 0, m_gw = 0, m_remote_bssid = 0,
120         m_config_port = 0, m_trap_port = 0, m_fw_bcast = 0, m_sb_bcast = 0,
121         m_sb_ucast = 0;
122     char *pr_ports[2] = {
123         _("Ethernet"),
124         _("Wireless")
125     }, *cf_trap_ports[3] = {
126         _("Both"),
127         _("Ethernet"),
128         _("Wireless (can be risky)")
129     };
130     int i;
131     unsigned int trap_port = 0;
132
133     if (ap_type == ATMEL12350) {
134         sysTrapSwitch[5] = 0xE0;
135         sysTrapSwitch[6] = 0x3E;
136         operIPAddress[5] = 0xE0;
137         operIPAddress[6] = 0x3E;
138         operIPMask[5] = 0xE0;
139         operIPMask[6] = 0x3E;
140         operEthernetAddress[5] = 0xE0;
141         operEthernetAddress[6] = 0x3E;
142         operGateway[5] = 0xE0;
143         operGateway[6] = 0x3E;
144         operDHCP[5] = 0xE0;
145         operDHCP[6] = 0x3E;
146         operPrimaryPort[5] = 0xE0;
147         operPrimaryPort[6] = 0x3E;
148         operConfigurationPort[5] = 0xE0;
149         operConfigurationPort[6] = 0x3E;
150         operIPFilter[5] = 0xE0;
151         operIPFilter[6] = 0x3E;
152         operForwarbBcast[5] = 0xE0;
153         operForwarbBcast[6] = 0x3E;
154         operSendBackBcast[5] = 0xE0;
155         operSendBackBcast[6] = 0x3E;
156         operSendBackUnicast[5] = 0xE0;
157         operSendBackUnicast[6] = 0x3E;
158         bridgeOperationalMode[5] = 0xE0;
159         bridgeOperationalMode[6] = 0x3E;
160         bridgeRemoteBridgeBSSID[5] = 0xE0;
161         bridgeRemoteBridgeBSSID[6] = 0x3E;
162     }
163
164     for (i = 0; i < 15; i++) {
165         varbinds[i].type = NULL_VALUE;
166         varbinds[i].len_val = 0;
167         varbinds[i].len_oid = sizeof(sysTrapSwitch);
168     }
169
170     i = 0;
171
172     varbinds[i++].oid = sysTrapSwitch;
173     varbinds[i++].oid = operIPAddress;
174     varbinds[i++].oid = operIPMask;
175     varbinds[i++].oid = operEthernetAddress;
176     varbinds[i++].oid = operGateway;
177     varbinds[i++].oid = operDHCP;
178     varbinds[i++].oid = operPrimaryPort;
179     varbinds[i++].oid = operIPFilter;
180     varbinds[i++].oid = bridgeOperationalMode;
181     varbinds[i++].oid = bridgeRemoteBridgeBSSID;
182     if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ||
183         (ap_type == ATMEL12350)) {
184         varbinds[i++].oid = operConfigurationPort;
185         varbinds[i++].oid = operForwarbBcast;
186         varbinds[i++].oid = operSendBackBcast;
187         varbinds[i++].oid = operSendBackUnicast;
188     }
189     if (ap_type == ATMEL12350 &&
190         (ap_vendorext == GEMTEK || ap_vendorext == EZYNET)) {
191             varbinds[i++].oid = operTrapPort;
192     }
193
194     print_help(WAIT_RET);
195     if (snmp(varbinds, i, GET) < i) {
196         print_helperr(ERR_RET);
197         goto exit;
198     }
199
200     print_top(NULL, _("Bridging"));
201
202     sprintf(message, "%s%02X%02X%02X%02X%02X%02X", MAC,
203             varbinds[3].value[0] & 0xFF,
204             varbinds[3].value[1] & 0xFF,
205             varbinds[3].value[2] & 0xFF,
206             varbinds[3].value[3] & 0xFF,
207             varbinds[3].value[4] & 0xFF,
208             varbinds[3].value[5] & 0xFF);
209     mvwaddstr(main_sub, 0, 0, message);
210
211     memcpy(&ip.s_addr, varbinds[1].value, 4);
212     sprintf(message, "%s%s", IPADDR, inet_ntoa(ip));
213     mvwaddstr(main_sub, 1, 0, message);
214
215     memcpy(&mask.s_addr, varbinds[2].value, 4);
216     sprintf(message, "%s%s", NETMASK, inet_ntoa(mask));
217     mvwaddstr(main_sub, 1, 24, message);
218
219     memcpy(&gw.s_addr, varbinds[4].value, 4);
220     sprintf(message, "%s%s", GATEWAY, inet_ntoa(gw));
221     mvwaddstr(main_sub, 2, 0, message);
222
223     filter = *(varbinds[7].value);
224     sprintf(message, "%s%s", IP_FILTER, (filter == 1) ? ON : OFF);
225     mvwaddstr(main_sub, 3, 0, message);
226
227 /*
228     if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES) {
229         sprintf(message, "%s%02X%02X%02X%02X%02X%02X", SB_ATTMAC,
230                 *(varbinds[6].value +0) & 0xFF, *(varbinds[6].value +1) & 0xFF,
231                 *(varbinds[6].value +2) & 0xFF, *(varbinds[6].value +3) & 0xFF,
232                 *(varbinds[6].value +4) & 0xFF, *(varbinds[6].value +5) & 0xFF);
233     } else {
234 */
235         primary_port = *(varbinds[6].value);
236         if (primary_port < 1 || primary_port > 2) {
237             primary_port = 1;
238         }
239         sprintf(message, "%s%s", PR_PORT, pr_ports[primary_port - 1]);
240 /*
241     }
242 */
243     mvwaddstr(main_sub, 4, 0, message);
244
245     dhcp = *(varbinds[5].value);
246     sprintf(message, "%s%s", DHCP, (dhcp == 1) ? ON : OFF);
247     mvwaddstr(main_sub, 5, 0, message);
248
249     memcpy(RemoteBSSID, varbinds[9].value, 6);
250     if ((bridge_mode = *(varbinds[8].value)) != 2) {
251         sprintf(message, "%s%02X%02X%02X%02X%02X%02X", REMOTE_MAC,
252                 *(RemoteBSSID + 0) & 0xFF, *(RemoteBSSID + 1) & 0xFF,
253                 *(RemoteBSSID + 2) & 0xFF, *(RemoteBSSID + 3) & 0xFF,
254                 *(RemoteBSSID + 4) & 0xFF, *(RemoteBSSID + 5) & 0xFF);
255         mvwaddstr(main_sub, 7, 0, message);
256     }
257     if (bridge_mode > 5)
258         bridge_mode  = 6;
259     sprintf(message, "%s%s", OPER, bridge_modes[bridge_mode - 1]);
260     mvwaddstr(main_sub, 6, 0, message);
261
262     traps = *(varbinds[0].value);
263     sprintf(message, "%s%s", TRAPS, (traps == 1) ? ON : OFF);
264     mvwaddstr(main_sub, 8, 0, message);
265
266     if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ||
267         ap_type == ATMEL12350) {
268         config_port = *(varbinds[10].value);
269         sprintf(message, "%s%s", CF_PORT, cf_trap_ports[config_port]);
270         mvwaddstr(main_sub, 9, 0, message);
271
272         fw_bcast = *(varbinds[11].value);
273         sprintf(message, "%s%s", FW_BCAST, (fw_bcast == 1) ? ON : OFF);
274         mvwaddstr(main_sub, 10, 0, message);
275
276         sb_bcast = *(varbinds[12].value);
277         sprintf(message, "%s%s", SB_BCAST, (sb_bcast == 1) ? ON : OFF);
278         mvwaddstr(main_sub, 11, 0, message);
279
280         sb_ucast = *(varbinds[13].value);
281         sprintf(message, "%s%s", SB_UCAST, (sb_ucast == 1) ? ON : OFF);
282         mvwaddstr(main_sub, 12, 0, message);
283     }
284
285     if (ap_type == ATMEL12350 &&
286         (ap_vendorext == GEMTEK || ap_vendorext == EZYNET)) {
287         for (i = 0; i < varbinds[14].len_val;
288             trap_port += varbinds[14].value[i] *
289             (1 << ((varbinds[14].len_val - i - 1) * 8)), i++);
290         sprintf(message, "%s%u", TRAP_PORT, trap_port);
291         mvwaddstr(main_sub, 13, 0, message);
292     }
293
294     wrefresh(main_sub);
295     noecho();
296
297     print_help(HELP);
298     while (1) {
299         switch (getch()) {
300         case 'I':
301         case 'i':
302             get_ip(&ip, 1, strlen(IPADDR), HELP);
303             m_ip = 1;
304             continue;
305         case 'N':
306         case 'n':
307             get_mask(&mask, 1, strlen(IPADDR) + 16 + strlen(NETMASK), HELP);
308             m_mask = 1;
309             continue;
310         case 'G':
311         case 'g':
312             get_ip(&gw, 2, strlen(GATEWAY), HELP);
313             m_gw = 1;
314             continue;
315         case 'F':
316         case 'f':
317             filter = on_off(3, strlen(IP_FILTER));
318             clear_main_new(3, 4);
319             print_menusel(3, 0, IP_FILTER, (filter == 1) ? ON : OFF);
320             m_filter = 1;
321             continue;
322         case 'P':
323         case 'p':
324 /*
325             if (ap_type == ATMEL410 && ap_vendorext == SBRIDGES)
326                 continue;
327 */
328             primary_port = menu_choose(4, strlen(PR_PORT), pr_ports, 2) + 1;
329             clear_main_new(4, 5);
330             print_menusel(4, 0, PR_PORT, pr_ports[primary_port - 1]);
331             m_primary_port = 1;
332             continue;
333         case 'D':
334         case 'd':
335             dhcp = on_off(5, strlen(DHCP));
336             clear_main_new(5, 6);
337             print_menusel(5, 0, DHCP, (dhcp == 1) ? ON : OFF);
338             m_dhcp = 1;
339             continue;
340         case 'O':
341         case 'o':
342             bridge_mode = menu_choose(6, strlen(OPER), bridge_modes, 5) + 1;
343             clear_main_new(6, 8);
344             print_menusel(6, 0, OPER, bridge_modes[bridge_mode - 1]);
345             if (bridge_mode != 2) {
346                 sprintf(message, "%02X%02X%02X%02X%02X%02X",
347                         *(RemoteBSSID + 0) & 0xFF,
348                         *(RemoteBSSID + 1) & 0xFF,
349                         *(RemoteBSSID + 2) & 0xFF,
350                         *(RemoteBSSID + 3) & 0xFF,
351                         *(RemoteBSSID + 4) & 0xFF,
352                         *(RemoteBSSID + 5) & 0xFF);
353                 print_menusel(7, 0, REMOTE_MAC, message);
354             }
355             m_bridge_mode = 1;
356             continue;
357         case 'M':
358         case 'm':
359             if (bridge_mode == 2)
360                 continue;
361
362             get_mac(RemoteBSSID, 7, strlen(REMOTE_MAC));
363 /*          mvwaddstr(main_sub, 7, 21, "  :  :  :  :  :  ");
364             for (i = 0; i < 6; i++) {
365                 get_value(message, 7, 21 + i * 3, 3, ANY_STRING, 0, 0, NULL);
366                 RemoteBSSID[i] = strtol(message, NULL, 16);
367             }
368             sprintf(message, "%s%02X%02X%02X%02X%02X%02X", REMOTE_MAC,
369                 *(RemoteBSSID + 0) & 0xFF, *(RemoteBSSID + 1) & 0xFF,
370                 *(RemoteBSSID + 2) & 0xFF, *(RemoteBSSID + 3) & 0xFF,
371                 *(RemoteBSSID + 4) & 0xFF, *(RemoteBSSID + 5) & 0xFF);
372 */
373             m_remote_bssid = 1;
374             continue;
375         case 'S':
376         case 's':
377             traps = on_off(8, strlen(TRAPS));
378             clear_main_new(8, 9);
379             print_menusel(8, 0, TRAPS, (traps == 1) ? ON : OFF);
380             m_traps = 1;
381             continue;
382         case 'C':
383         case 'c':
384             if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ||
385                 ap_type == ATMEL12350) {
386                 config_port = menu_choose(9, strlen(CF_PORT), cf_trap_ports, 3);
387                 clear_main_new(9, 10);
388                 print_menusel(9, 0, CF_PORT, cf_trap_ports[config_port]);
389                 m_config_port = 1;
390             }
391             continue;
392         case 'R':
393         case 'r':
394             if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ||
395                 ap_type == ATMEL12350) {
396                 fw_bcast = on_off(10, strlen(FW_BCAST));
397                 clear_main_new(10, 11);
398                 print_menusel(10, 0, FW_BCAST, (fw_bcast == 1) ? ON : OFF);
399                 m_fw_bcast = 1;
400             }
401             continue;
402         case 'B':
403         case 'b':
404             if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ||
405                 ap_type == ATMEL12350) {
406                 sb_bcast = on_off(11, strlen(SB_BCAST));
407                 clear_main_new(11, 12);
408                 print_menusel(11, 0, SB_BCAST, (sb_bcast == 1) ? ON : OFF);
409                 m_sb_bcast = 1;
410             }
411             continue;
412         case 'U':
413         case 'u':
414             if ((ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ||
415                 ap_type == ATMEL12350) {
416                 sb_ucast = on_off(12, strlen(SB_UCAST));
417                 clear_main_new(12, 13);
418                 print_menusel(12, 0, SB_UCAST, (sb_ucast == 1) ? ON : OFF);
419                 m_sb_ucast = 1;
420             }
421             continue;
422         case 'T':
423         case 't':
424             if (ap_type == ATMEL12350 &&
425                 (ap_vendorext == GEMTEK || ap_vendorext == EZYNET)) {
426                 get_value(message, 13, strlen(TRAP_PORT), 6, INT_STRING,
427                     0, 65535, HELP);
428                 trap_port = atoi(message);
429                 m_trap_port = 1;
430             }
431             continue;
432         case 'w':
433         case 'W':
434             i = 0;
435             if (m_filter) {
436                 varbinds[i].oid = operIPFilter;
437                 varbinds[i].len_oid = sizeof(operIPFilter);
438                 varbinds[i].type = INT_VALUE;
439                 varbinds[i].value = (char *) &filter;
440                 varbinds[i].len_val = 1;
441                 i++;
442             }
443             if (m_primary_port) {
444                 varbinds[i].oid = operPrimaryPort;
445                 varbinds[i].len_oid = sizeof(operPrimaryPort);
446                 varbinds[i].type = INT_VALUE;
447                 varbinds[i].value = (char *) &primary_port;
448                 varbinds[i].len_val = 1;
449                 i++;
450             }
451             if (m_dhcp) {
452                 varbinds[i].oid = operDHCP;
453                 varbinds[i].len_oid = sizeof(operDHCP);
454                 varbinds[i].type = INT_VALUE;
455                 varbinds[i].value = (char *) &dhcp;
456                 varbinds[i].len_val = 1;
457                 i++;
458             }
459             if (m_ip) {
460                 varbinds[i].oid = operIPAddress;
461                 varbinds[i].len_oid = sizeof(operIPAddress);
462                 ip.s_addr = htonl(ip.s_addr);
463                 ip.s_addr = swap4(ip.s_addr);
464                 varbinds[i].value = (char *) &ip.s_addr;
465                 varbinds[i].len_val = 4;
466                 varbinds[i].type = INT_VALUE;
467                 i++;
468             }
469             if (m_mask) {
470                 varbinds[i].oid = operIPMask;
471                 varbinds[i].len_oid = sizeof(operIPMask);
472                 mask.s_addr = htonl(mask.s_addr);
473                 mask.s_addr = swap4(mask.s_addr);
474                 varbinds[i].value = (char *) &mask.s_addr;
475                 varbinds[i].len_val = 4;
476                 varbinds[i].type = INT_VALUE;
477                 i++;
478             }
479             if (m_gw) {
480                 varbinds[i].oid = operGateway;
481                 gw.s_addr = htonl(gw.s_addr);
482                 gw.s_addr = swap4(gw.s_addr);
483                 varbinds[i].len_oid = sizeof(operGateway);
484                 varbinds[i].value = (char *) &gw.s_addr;
485                 varbinds[i].len_val = 4;
486                 varbinds[i].type = INT_VALUE;
487                 i++;
488             }
489             if (m_traps) {
490                 varbinds[i].oid = sysTrapSwitch;
491                 varbinds[i].len_oid = sizeof(sysTrapSwitch);
492                 varbinds[i].value = &traps;
493                 varbinds[i].len_val = 1;
494                 varbinds[i].type = INT_VALUE;
495                 i++;
496             }
497             if (m_bridge_mode) {
498                 varbinds[i].oid = bridgeOperationalMode;
499                 varbinds[i].len_oid = sizeof(bridgeOperationalMode);
500                 varbinds[i].value = (char *) &bridge_mode;
501                 varbinds[i].len_val = 1;
502                 varbinds[i].type = INT_VALUE;
503                 i++;
504             }
505             if (m_remote_bssid) {
506                 varbinds[i].oid = bridgeRemoteBridgeBSSID;
507                 varbinds[i].len_oid = sizeof(bridgeRemoteBridgeBSSID);
508                 varbinds[i].value = RemoteBSSID;
509                 varbinds[i].len_val = 6;
510                 varbinds[i].type = STRING_VALUE;
511                 i++;
512             }
513             if (m_config_port) {
514                 varbinds[i].oid = operConfigurationPort;
515                 varbinds[i].len_oid = sizeof(operConfigurationPort);
516                 varbinds[i].type = INT_VALUE;
517                 varbinds[i].value = (char *) &config_port;
518                 varbinds[i].len_val = 1;
519                 i++;
520             }
521             if (m_fw_bcast) {
522                 varbinds[i].oid = operForwarbBcast;
523                 varbinds[i].len_oid = sizeof(operForwarbBcast);
524                 varbinds[i].type = INT_VALUE;
525                 varbinds[i].value = (char *) &fw_bcast;
526                 varbinds[i].len_val = 1;
527                 i++;
528             }
529             if (m_sb_bcast) {
530                 varbinds[i].oid = operSendBackBcast;
531                 varbinds[i].len_oid = sizeof(operSendBackBcast);
532                 varbinds[i].type = INT_VALUE;
533                 varbinds[i].value = (char *) &sb_bcast;
534                 varbinds[i].len_val = 1;
535                 i++;
536             }
537             if (m_sb_ucast) {
538                 varbinds[i].oid = operSendBackUnicast;
539                 varbinds[i].len_oid = sizeof(operSendBackUnicast);
540                 varbinds[i].type = INT_VALUE;
541                 varbinds[i].value = (char *) &sb_ucast;
542                 varbinds[i].len_val = 1;
543                 i++;
544             }
545             if (m_trap_port) {
546                 int len_val;
547
548                 len_val = (trap_port > 0x7fff) ? 3 : (trap_port > 0x7f) ? 2 : 1;
549                 varbinds[i].oid = operTrapPort;
550                 varbinds[i].len_oid = sizeof(operTrapPort);
551                 varbinds[i].type = STRING_VALUE;
552                 varbinds[i].value = (char *) &trap_port;
553                 varbinds[i].len_val = len_val;
554                 i++;
555             }
556
557             print_help(WAIT_SET);
558             if (snmp(varbinds, i, SET) <= 0)
559                 print_helperr(ERR_SET);
560             else
561                 print_help(DONE_SET);
562             goto exit;
563         case 'Q':
564         case 'q':
565             goto quit;
566         }
567         continue;
568     }
569   exit:
570     getch();
571   quit:
572     print_top(NULL, NULL);
573     clear_main(0);
574 }
575