68
68
* In case of a duplicate in the IPTraf definition files and /etc/ethers,
69
69
* the IPTraf definition files take precedence.
72
void loaddesclist(struct desclist *list, unsigned int linktype, int withethers)
72
void loaddesclist(struct desclist *list, unsigned int linktype,
74
75
struct desclistent *ptmp = NULL;
76
77
char descline[140];
78
79
char etherline[140];
79
int i,j; /* counters used when parsing /etc/ethers */
80
int i, j; /* counters used when parsing /etc/ethers */
81
82
bzero(list, sizeof(struct desclist));
83
84
if (linktype == LINK_ETHERNET)
84
fd = fopen(ETHFILE, "r");
85
fd = fopen(ETHFILE, "r");
85
86
else if (linktype == LINK_FDDI)
86
fd = fopen(FDDIFILE, "r");
87
fd = fopen(FDDIFILE, "r");
91
92
while (!feof(fd)) {
92
ptmp = malloc(sizeof(struct desclistent));
97
bzero(ptmp, sizeof(struct desclistent));
99
fgets(descline, 140, fd);
101
if (strcmp(descline, "") == 0) {
105
strncpy(ptmp->rec.address, strtok(descline, ":"), 12);
106
desctoken = strtok(NULL, "\n");
108
if (desctoken != NULL)
109
strncpy(ptmp->rec.desc, desctoken, 64);
111
strcpy(ptmp->rec.desc, "");
93
ptmp = malloc(sizeof(struct desclistent));
98
bzero(ptmp, sizeof(struct desclistent));
100
fgets(descline, 140, fd);
102
if (strcmp(descline, "") == 0) {
106
strncpy(ptmp->rec.address, strtok(descline, ":"), 12);
107
desctoken = strtok(NULL, "\n");
109
if (desctoken != NULL)
110
strncpy(ptmp->rec.desc, desctoken, 64);
112
strcpy(ptmp->rec.desc, "");
113
114
add_desclist_node(list, ptmp);
119
120
* Loads MAC addresses defined in /etc/ethers. Contributed by
120
121
* Debian maintainter Frederic Peters <fpeters@debian.org>. Thanks
133
134
if (linktype != LINK_ETHERNET)
136
137
fd = fopen("/etc/ethers", "r");
141
142
while (!feof(fd)) {
142
ptmp = malloc(sizeof(struct desclistent));
147
bzero(ptmp, sizeof(struct desclistent));
148
bzero(descline, 140);
149
bzero(etherline, 140);
150
fgets(etherline, 140, fd);
153
* Convert /etc/ethers line to a descline
155
if (etherline[0] == '#' || etherline[0] == '\n' || etherline[0] == 0) {
160
if (strchr(etherline, '\n') )
161
strchr(etherline, '\n')[0] = 0;
164
for (i = 0; i < 20 && !isspace(etherline[i]); i++) {
165
if (etherline[i] == ':')
167
descline[j++] = tolower(etherline[i]);
172
* Skip over whitespace between MAC address and IP addr/host name
175
while (isspace(etherline[i++]))
178
strncat(descline, etherline + i - 1, 130);
180
if (strcmp(descline, "") == 0) {
185
strncpy(ptmp->rec.address, strtok(descline, ":"), 12);
186
desctoken = strtok(NULL, "\n");
188
if (desctoken != NULL)
189
strncpy(ptmp->rec.desc, desctoken, 64);
191
strcpy(ptmp->rec.desc, "");
143
ptmp = malloc(sizeof(struct desclistent));
148
bzero(ptmp, sizeof(struct desclistent));
149
bzero(descline, 140);
150
bzero(etherline, 140);
151
fgets(etherline, 140, fd);
154
* Convert /etc/ethers line to a descline
156
if (etherline[0] == '#' || etherline[0] == '\n'
157
|| etherline[0] == 0) {
162
if (strchr(etherline, '\n'))
163
strchr(etherline, '\n')[0] = 0;
166
for (i = 0; i < 20 && !isspace(etherline[i]); i++) {
167
if (etherline[i] == ':')
169
descline[j++] = tolower(etherline[i]);
174
* Skip over whitespace between MAC address and IP addr/host name
177
while (isspace(etherline[i++]));
179
strncat(descline, etherline + i - 1, 130);
181
if (strcmp(descline, "") == 0) {
186
strncpy(ptmp->rec.address, strtok(descline, ":"), 12);
187
desctoken = strtok(NULL, "\n");
189
if (desctoken != NULL)
190
strncpy(ptmp->rec.desc, desctoken, 64);
192
strcpy(ptmp->rec.desc, "");
193
194
add_desclist_node(list, ptmp);
203
204
struct desclistent *ptmp = list->head;
205
206
if (linktype == LINK_ETHERNET)
206
fd = fopen(ETHFILE, "w");
207
fd = fopen(ETHFILE, "w");
207
208
else if (linktype == LINK_FDDI)
208
fd = fopen(FDDIFILE, "w");
209
fd = fopen(FDDIFILE, "w");
214
215
while (ptmp != NULL) {
215
fprintf(fd, "%s:%s\n", ptmp->rec.address, ptmp->rec.desc);
216
ptmp = ptmp->next_entry;
216
fprintf(fd, "%s:%s\n", ptmp->rec.address, ptmp->rec.desc);
217
ptmp = ptmp->next_entry;
266
267
sprintf(sp_buf, "%%%dc", COLS - 2);
269
wattrset(win, PTRATTR);
271
waddch(win, ACS_RARROW);
275
wattrset(win, STDATTR);
279
if ((*node)->next_entry != NULL) {
280
*node = (*node)->next_entry;
288
wprintw(win, sp_buf, ' ');
291
wprintw(win, "%s %s", (*node)->rec.address,
297
if ((*node)->prev_entry != NULL) {
298
*node = (*node)->prev_entry;
305
wprintw(win, sp_buf, ' ');
307
wprintw(win, "%s %s", (*node)->rec.address,
270
wattrset(win, PTRATTR);
272
waddch(win, ACS_RARROW);
276
wattrset(win, STDATTR);
280
if ((*node)->next_entry != NULL) {
281
*node = (*node)->next_entry;
289
wprintw(win, sp_buf, ' ');
292
wprintw(win, "%s %s", (*node)->rec.address,
298
if ((*node)->prev_entry != NULL) {
299
*node = (*node)->prev_entry;
306
wprintw(win, sp_buf, ' ');
308
wprintw(win, "%s %s", (*node)->rec.address,
326
327
} while (!exitloop);
329
330
void selectdesc(struct desclist *list, struct desclistent **node,
333
334
struct scroll_list slist;
334
335
char descline[80];
336
337
if (list->head == NULL) {
337
tx_errbox("No descriptions", ANYKEY_MSG, &resp);
338
tx_errbox("No descriptions", ANYKEY_MSG, &resp);
341
342
*node = list->head;
342
343
tx_init_listbox(&slist, COLS, 20, 0, (LINES - 20) / 2,
343
STDATTR, BOXATTR, BARSTDATTR, HIGHATTR);
344
STDATTR, BOXATTR, BARSTDATTR, HIGHATTR);
345
346
tx_set_listbox_title(&slist, "Address", 1);
346
347
tx_set_listbox_title(&slist, "Description", 19);
348
349
while (*node != NULL) {
349
snprintf(descline, 80, "%-18s%s", (*node)->rec.address, (*node)->rec.desc);
350
snprintf(descline, 80, "%-18s%s", (*node)->rec.address,
350
352
tx_add_list_entry(&slist, (char *) (*node), descline);
351
353
(*node) = (*node)->next_entry;
354
356
tx_show_listbox(&slist);
355
357
tx_operate_listbox(&slist, &resp, aborted);
377
379
wattrset(win, DLGBOXATTR);
378
380
tx_colorwin(win);
379
box(win, ACS_VLINE, ACS_HLINE);
381
tx_box(win, ACS_VLINE, ACS_HLINE);
380
382
wmove(win, 6, 2 * COLS / 80);
382
384
wmove(win, 6, 20 * COLS / 80);
387
389
wprintw(win, "MAC Address:");
388
390
wmove(win, 4, 2 * COLS / 80);
389
391
wprintw(win, "Description:");
391
393
tx_initfields(&fieldlist, 3, 52, 10, (COLS - 52) / 2 + 6 * COLS / 80,
392
DLGTEXTATTR, FIELDATTR);
394
DLGTEXTATTR, FIELDATTR);
393
395
tx_addfield(&fieldlist, 12, 0, 0, initaddr);
394
396
tx_addfield(&fieldlist, 50, 2, 0, initdesc);
396
398
tx_fillfields(&fieldlist, aborted);
398
400
if (!(*aborted)) {
399
strcpy(rec->address, fieldlist.list->buf);
400
strcpy(rec->desc, fieldlist.list->nextfield->buf);
401
strcpy(rec->address, fieldlist.list->buf);
402
strcpy(rec->desc, fieldlist.list->nextfield->buf);
402
404
tx_destroyfields(&fieldlist);
403
405
del_panel(panel);
413
415
descdlg(&rec, "", "", &aborted);
416
ptmp = malloc(sizeof(struct desclistent));
417
if (list->head == NULL) {
419
ptmp->prev_entry = NULL;
421
ptmp->prev_entry = list->tail;
422
list->tail->next_entry = ptmp;
418
ptmp = malloc(sizeof(struct desclistent));
419
if (list->head == NULL) {
421
ptmp->prev_entry = NULL;
423
ptmp->prev_entry = list->tail;
424
list->tail->next_entry = ptmp;
426
ptmp->next_entry = NULL;
427
memcpy(&(ptmp->rec), &rec, sizeof(struct descrec));
428
ptmp->next_entry = NULL;
429
memcpy(&(ptmp->rec), &rec, sizeof(struct descrec));
449
451
selectdesc(list, &ptmp, &aborted);
452
if (ptmp->prev_entry != NULL)
453
ptmp->prev_entry->next_entry = ptmp->next_entry;
455
list->head = ptmp->next_entry;
457
if (ptmp->next_entry != NULL)
458
ptmp->next_entry->prev_entry = ptmp->prev_entry;
460
list->tail = ptmp->prev_entry;
454
if (ptmp->prev_entry != NULL)
455
ptmp->prev_entry->next_entry = ptmp->next_entry;
457
list->head = ptmp->next_entry;
459
if (ptmp->next_entry != NULL)
460
ptmp->next_entry->prev_entry = ptmp->prev_entry;
462
list->tail = ptmp->prev_entry;
474
476
loaddesclist(&list, linktype, WITHOUTETCETHERS);
476
478
tx_initmenu(&menu, 7, 31, (LINES - 6) / 2, (COLS - 31) / 2,
477
BOXATTR, STDATTR, HIGHATTR, BARSTDATTR, BARHIGHATTR, DESCATTR);
479
BOXATTR, STDATTR, HIGHATTR, BARSTDATTR, BARHIGHATTR,
478
481
tx_additem(&menu, " ^A^dd description...",
479
"Adds a description for a MAC address");
482
"Adds a description for a MAC address");
480
483
tx_additem(&menu, " ^E^dit description...",
481
"Modifies an existing MAC address description");
484
"Modifies an existing MAC address description");
482
485
tx_additem(&menu, " ^D^elete description...",
483
"Deletes an existing MAC address description");
486
"Deletes an existing MAC address description");
484
487
tx_additem(&menu, NULL, NULL);
485
488
tx_additem(&menu, " E^x^it menu", "Returns to the main menu");
489
tx_operatemenu(&menu, &row, &aborted);
492
tx_operatemenu(&menu, &row, &aborted);
502
505
} while (row != 5);
504
507
tx_destroymenu(&menu);