add contrib directory & contents

This commit is contained in:
marschap
2006-02-25 18:23:24 +00:00
parent d0d8b1d9f1
commit 26904e9637
38 changed files with 6449 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
What do these patches do ?
==========================
1. HKEY - Hybrid Right/Left Key option in LCDd.conf
If selected, the same config works on 4 or 6 key pads, any key wakes up
the menus, the keys behave a bit more intuitively and if you have a menu
w/ only ring or slider you can't get stuck in them on a 4 key system.
Ultimately, I wonder if the key processing could be simplified a bit, it
currently has 3 levels, that might be able to be flattened, I've been
pondering it and don't have a simple sol'n yet, but feel like there's
one there, so I'll keep thinking on it for now.
2. OPT - adds options to the LCDd.conf for;
storing the default display string on the CFontz633.c, we use this to
put up a "starting" message for reboot for example.
setting the main menu name - which show's up on the LCD menu list, we
give it a more meaningful name like "admin" for the menus, instead of
"lcdproc"
setting the goodbye msg - which we set to "shutting down", instead of
"Thanks for using lcdproc+linux"
3. SEG - adds the ability to get a stack trace for the LCDd daemon. I
didn't actually catch a useful trace w/ it, but might be a nice
diagnostic ability or not worth the trouble, maybe gdb's just easier
when you need?
+547
View File
@@ -0,0 +1,547 @@
diff --exclude='*.wanjet' --exclude='.??*' --exclude=config.h --exclude='*.orig' --exclude=Makefile --exclude='*.o' --exclude=Doxyfile --exclude='*.a' --exclude=config.log --exclude=config.status --exclude='init-*' -Nuarp server/menu.c server.HKEY/menu.c
--- server/menu.c 2006-01-26 19:47:59.000000000 -0800
+++ server.HKEY/menu.c 2006-02-21 09:21:25.000000000 -0800
@@ -39,6 +39,13 @@
#include "screen.h"
#include "widget.h"
+#ifndef HKEY //hybrid keys
+#include "shared/configfile.h"
+
+extern int hybrid_left_key;
+extern int hybrid_right_key;
+#endif //HKEY
+
/** Basicly a patched version of LL_GetByIndex() that ignores hidden
* entries completely. (But it takes a menu as an argument.) */
static void *
@@ -559,12 +566,86 @@ MenuResult menu_process_input(Menu *menu
return MENURESULT_ERROR;
switch (token) {
+ case MENUTOKEN_LEFT:
+ if (!extended)
+ return MENURESULT_NONE;
+#ifndef HKEY //hybrid key left
+ /*
+ * hybrid left key just fall through to menu key
+ */
+ if (!hybrid_left_key) {
+ subitem = menu_get_subitem (menu, menu->data.menu.selector_pos);
+ if (subitem == NULL)
+ break;
+ switch (subitem->type) {
+ case MENUITEM_CHECKBOX:
+ /* note: this dangerous looking code works since
+ * CheckboxValue is an enum >= 0. */
+ if (subitem->data.checkbox.allow_gray) {
+ subitem->data.checkbox.value = (subitem->data.checkbox.value - 1) % 3;
+ }
+ else {
+ subitem->data.checkbox.value = (subitem->data.checkbox.value - 1) % 2;
+ }
+ if (subitem->event_func)
+ subitem->event_func (subitem, MENUEVENT_UPDATE);
+ return MENURESULT_NONE;
+ case MENUITEM_RING:
+ /* ring: jump to the end if beginning is reached */
+ subitem->data.ring.value = (subitem->data.ring.value < 1)
+ ? LL_Length (subitem->data.ring.strings) - 1
+ : (subitem->data.ring.value - 1) % LL_Length (subitem->data.ring.strings);
+ if (subitem->event_func)
+ subitem->event_func (subitem, MENUEVENT_UPDATE);
+ return MENURESULT_NONE;
+ default:
+ break;
+ }
+ return MENURESULT_NONE;
+ }
+#endif //HKEY
case MENUTOKEN_MENU:
subitem = menu_get_item_for_predecessor_check(menu);
if ( ! subitem)
return MENURESULT_ERROR;
return menuitem_predecessor2menuresult(
subitem->predecessor_id, MENURESULT_CLOSE);
+ case MENUTOKEN_RIGHT:
+#ifndef HKEY //hybrid key right
+ /*
+ * hybrid right key just fall through to enter key
+ */
+ if (!hybrid_right_key) {
+ if (!extended) /* Can you get a MENUTOKEN_RIGHT w/o a RightKey defined, this code maybe be unecessary */
+ return MENURESULT_NONE;
+
+ subitem = menu_get_subitem(menu, menu->data.menu.selector_pos);
+ if (subitem == NULL)
+ break;
+ switch (subitem->type) {
+ case MENUITEM_CHECKBOX:
+ if (subitem->data.checkbox.allow_gray) {
+ subitem->data.checkbox.value = (subitem->data.checkbox.value + 1) % 3;
+ }
+ else {
+ subitem->data.checkbox.value = (subitem->data.checkbox.value + 1) % 2;
+ }
+ if (subitem->event_func)
+ subitem->event_func (subitem, MENUEVENT_UPDATE);
+ return MENURESULT_NONE;
+ case MENUITEM_RING:
+ subitem->data.ring.value = (subitem->data.ring.value + 1) % LL_Length (subitem->data.ring.strings);
+ if (subitem->event_func)
+ subitem->event_func (subitem, MENUEVENT_UPDATE);
+ return MENURESULT_NONE;
+ case MENUITEM_MENU:
+ return MENURESULT_ENTER;
+ default:
+ break;
+ }
+ return MENURESULT_NONE;
+ }
+#endif //HKEY
case MENUTOKEN_ENTER:
subitem = menu_get_subitem (menu, menu->data.menu.selector_pos);
if (!subitem)
@@ -609,6 +690,18 @@ MenuResult menu_process_input(Menu *menu
menu->data.menu.scroll --;
}
else if (menu->data.menu.selector_pos == 0) {
+#ifndef HKEY //hybrid key left
+ if ( hybrid_left_key ) {
+ /*
+ * If this menu has only checkbox's and/or rings
+ * need a key to get back from this menu on a 4 key pad
+ */
+ subitem = menu_get_item_for_predecessor_check(menu);
+ if ( subitem && ((subitem->type == MENUITEM_CHECKBOX) || (subitem->type == MENUITEM_RING)))
+ return menuitem_predecessor2menuresult(
+ subitem->predecessor_id, MENURESULT_CLOSE);
+ }
+#endif // HKEY
// wrap around to last menu entry
menu->data.menu.selector_pos = menu_visible_item_count(menu) - 1;
menu->data.menu.scroll = menu->data.menu.selector_pos + 2 - display_props->height;
@@ -626,67 +719,6 @@ MenuResult menu_process_input(Menu *menu
menu->data.menu.scroll = 0;
}
return MENURESULT_NONE;
- case MENUTOKEN_LEFT:
- if (!extended)
- return MENURESULT_NONE;
-
- subitem = menu_get_subitem (menu, menu->data.menu.selector_pos);
- if (subitem == NULL)
- break;
- switch (subitem->type) {
- case MENUITEM_CHECKBOX:
- /* note: this dangerous looking code works since
- * CheckboxValue is an enum >= 0. */
- if (subitem->data.checkbox.allow_gray) {
- subitem->data.checkbox.value = (subitem->data.checkbox.value - 1) % 3;
- }
- else {
- subitem->data.checkbox.value = (subitem->data.checkbox.value - 1) % 2;
- }
- if (subitem->event_func)
- subitem->event_func (subitem, MENUEVENT_UPDATE);
- return MENURESULT_NONE;
- case MENUITEM_RING:
- /* ring: jump to the end if beginning is reached */
- subitem->data.ring.value = (subitem->data.ring.value < 1)
- ? LL_Length (subitem->data.ring.strings) - 1
- : (subitem->data.ring.value - 1) % LL_Length (subitem->data.ring.strings);
- if (subitem->event_func)
- subitem->event_func (subitem, MENUEVENT_UPDATE);
- return MENURESULT_NONE;
- default:
- break;
- }
- return MENURESULT_NONE;
- case MENUTOKEN_RIGHT:
- if (!extended)
- return MENURESULT_NONE;
-
- subitem = menu_get_subitem(menu, menu->data.menu.selector_pos);
- if (subitem == NULL)
- break;
- switch (subitem->type) {
- case MENUITEM_CHECKBOX:
- if (subitem->data.checkbox.allow_gray) {
- subitem->data.checkbox.value = (subitem->data.checkbox.value + 1) % 3;
- }
- else {
- subitem->data.checkbox.value = (subitem->data.checkbox.value + 1) % 2;
- }
- if (subitem->event_func)
- subitem->event_func (subitem, MENUEVENT_UPDATE);
- return MENURESULT_NONE;
- case MENUITEM_RING:
- subitem->data.ring.value = (subitem->data.ring.value + 1) % LL_Length (subitem->data.ring.strings);
- if (subitem->event_func)
- subitem->event_func (subitem, MENUEVENT_UPDATE);
- return MENURESULT_NONE;
- case MENUITEM_MENU:
- return MENURESULT_ENTER;
- default:
- break;
- }
- return MENURESULT_NONE;
case MENUTOKEN_OTHER:
/* TODO: move to the selected number and enter it */
return MENURESULT_NONE;
diff --exclude='*.wanjet' --exclude='.??*' --exclude=config.h --exclude='*.orig' --exclude=Makefile --exclude='*.o' --exclude=Doxyfile --exclude='*.a' --exclude=config.log --exclude=config.status --exclude='init-*' -Nuarp server/menuitem.c server.HKEY/menuitem.c
--- server/menuitem.c 2006-01-26 19:47:59.000000000 -0800
+++ server.HKEY/menuitem.c 2006-02-21 09:22:53.000000000 -0800
@@ -84,6 +84,10 @@ const IpSstringProperties IPinfo[] = {
{ 39, ':', 16, 4, 65535, { 4096, 256, 16, 1, 0 }, "%04x", verify_ipv6, "0:0:0:0:0:0:0:0" }
};
+#ifndef HKEY // hybrid keys
+extern int hybrid_left_key;
+extern int hybrid_right_key;
+#endif //HKEY
/******** MENU UTILITY FUNCTIONS ********/
@@ -983,26 +987,38 @@ MenuResult menuitem_process_input_slider
return MENURESULT_ERROR;
switch (token) {
- case MENUTOKEN_MENU:
- return menuitem_predecessor2menuresult(
- item->predecessor_id, MENURESULT_CLOSE);
- case MENUTOKEN_ENTER:
- return menuitem_successor2menuresult(
- item->successor_id, MENURESULT_CLOSE);
case MENUTOKEN_UP:
case MENUTOKEN_RIGHT:
- item->data.slider.value = min (item->data.slider.maxvalue,
+#ifndef HKEY //hybrid key right
+ if ( !hybrid_right_key || token == MENUTOKEN_UP ) {
+#endif /*HKEY*/
+ item->data.slider.value = min (item->data.slider.maxvalue,
item->data.slider.value + item->data.slider.stepsize);
- if (item->event_func)
- item->event_func (item, MENUEVENT_PLUS);
- return MENURESULT_NONE;
+ if (item->event_func)
+ item->event_func (item, MENUEVENT_PLUS);
+ return MENURESULT_NONE;
+#ifndef HKEY //hybrid key right
+ } /* hybrid right key fall through to enter */
+#endif /*HKEY*/
+ case MENUTOKEN_ENTER:
+ return menuitem_successor2menuresult(
+ item->successor_id, MENURESULT_CLOSE);
case MENUTOKEN_DOWN:
case MENUTOKEN_LEFT:
- item->data.slider.value = max (item->data.slider.minvalue,
+#ifndef HKEY //hybrid key left
+ if ( !hybrid_left_key || token == MENUTOKEN_DOWN ) {
+#endif /*HKEY*/
+ item->data.slider.value = max (item->data.slider.minvalue,
item->data.slider.value - item->data.slider.stepsize);
- if (item->event_func)
- item->event_func (item, MENUEVENT_MINUS);
- return MENURESULT_NONE;
+ if (item->event_func)
+ item->event_func (item, MENUEVENT_MINUS);
+ return MENURESULT_NONE;
+#ifndef HKEY //hybrid key left
+ } /* hybrid left key fall through to menu */
+#endif /*HKEY*/
+ case MENUTOKEN_MENU:
+ return menuitem_predecessor2menuresult(
+ item->predecessor_id, MENURESULT_CLOSE);
case MENUTOKEN_OTHER:
default:
break;
@@ -1037,6 +1053,21 @@ MenuResult menuitem_process_input_numeri
item->data.numeric.error_code = 0;
switch (token) {
+ case MENUTOKEN_LEFT:
+ /* The user wants to go to back a digit */
+ if (pos > 0) {
+ item->data.numeric.edit_pos--;
+ if (item->data.numeric.edit_offs > item->data.numeric.edit_pos)
+ item->data.numeric.edit_offs = item->data.numeric.edit_pos;
+#ifndef HKEY //hybrid key left
+ if( hybrid_left_key ) return MENURESULT_NONE;
+ }
+ if( !hybrid_left_key ) return MENURESULT_NONE;
+ /* fall through to MENU */
+#else
+ }
+ return MENURESULT_NONE;
+#endif /*HKEY*/
case MENUTOKEN_MENU:
if (pos == 0) {
return menuitem_predecessor2menuresult(
@@ -1047,6 +1078,21 @@ MenuResult menuitem_process_input_numeri
menuitem_reset_numeric(item);
}
return MENURESULT_NONE;
+ case MENUTOKEN_RIGHT:
+ /* The user wants to go to next digit */
+ if (str[pos] != '\0' && pos < max_len) {
+ item->data.numeric.edit_pos++;
+ if (pos >= display_props->width - 2)
+ item->data.numeric.edit_offs++;
+#ifndef HKEY //hybrid key right
+ if( hybrid_right_key ) return MENURESULT_NONE;
+ }
+ if( !hybrid_right_key ) return MENURESULT_NONE;
+ /* fall through to ENTER */
+#else
+ }
+ return MENURESULT_NONE;
+#endif /*HKEY*/
case MENUTOKEN_ENTER:
if ((extended) || (str[pos] == '\0')) {
int value;
@@ -1131,22 +1177,6 @@ MenuResult menuitem_process_input_numeri
}
}
return MENURESULT_NONE;
- case MENUTOKEN_RIGHT:
- /* The user wants to go to next digit */
- if (str[pos] != '\0' && pos < max_len) {
- item->data.numeric.edit_pos++;
- if (pos >= display_props->width - 2)
- item->data.numeric.edit_offs++;
- }
- return MENURESULT_NONE;
- case MENUTOKEN_LEFT:
- /* The user wants to go to back a digit */
- if (pos > 0) {
- item->data.numeric.edit_pos--;
- if (item->data.numeric.edit_offs > item->data.numeric.edit_pos)
- item->data.numeric.edit_offs = item->data.numeric.edit_pos;
- }
- return MENURESULT_NONE;
case MENUTOKEN_OTHER:
if (pos >= max_len) {
/* We're not allowed to add anything anymore */
@@ -1196,6 +1226,21 @@ MenuResult menuitem_process_input_alpha
item->data.alpha.error_code = 0;
switch (token) {
+ case MENUTOKEN_LEFT:
+ /* The user wants to go to back a digit */
+ if (pos > 0) {
+ item->data.alpha.edit_pos--;
+ if (item->data.alpha.edit_offs > item->data.alpha.edit_pos)
+ item->data.alpha.edit_offs = item->data.alpha.edit_pos;
+#ifndef HKEY //hybrid key left
+ if( hybrid_left_key ) return MENURESULT_NONE;
+ }
+ if( !hybrid_left_key ) return MENURESULT_NONE;
+ /* fall through to MENU */
+#else
+ }
+ return MENURESULT_NONE;
+#endif /*HKEY*/
case MENUTOKEN_MENU:
if (pos == 0) {
return menuitem_predecessor2menuresult(
@@ -1206,6 +1251,22 @@ MenuResult menuitem_process_input_alpha
menuitem_reset_alpha(item);
}
return MENURESULT_NONE;
+ case MENUTOKEN_RIGHT:
+ /* The user wants to go to next digit */
+ if (str[item->data.alpha.edit_pos] != '\0' &&
+ pos < item->data.alpha.maxlength - 1) {
+ item->data.alpha.edit_pos++;
+ if (pos >= display_props->width - 2)
+ item->data.alpha.edit_offs++;
+#ifndef HKEY //hybrid key right
+ if( hybrid_right_key ) return MENURESULT_NONE;
+ }
+ if( !hybrid_right_key ) return MENURESULT_NONE;
+ /* fall through to ENTER */
+#else
+ }
+ return MENURESULT_NONE;
+#endif /*HKEY*/
case MENUTOKEN_ENTER:
if ((extended) || (str[item->data.alpha.edit_pos] == '\0')) {
/* The user completed his input */
@@ -1278,23 +1339,6 @@ MenuResult menuitem_process_input_alpha
}
}
return MENURESULT_NONE;
- case MENUTOKEN_RIGHT:
- /* The user wants to go to next digit */
- if (str[item->data.alpha.edit_pos] != '\0' &&
- pos < item->data.alpha.maxlength - 1) {
- item->data.alpha.edit_pos++;
- if (pos >= display_props->width - 2)
- item->data.alpha.edit_offs++;
- }
- return MENURESULT_NONE;
- case MENUTOKEN_LEFT:
- /* The user wants to go to back a digit */
- if (pos > 0) {
- item->data.alpha.edit_pos--;
- if (item->data.alpha.edit_offs > item->data.alpha.edit_pos)
- item->data.alpha.edit_offs = item->data.alpha.edit_pos;
- }
- return MENURESULT_NONE;
case MENUTOKEN_OTHER:
if (pos >= item->data.alpha.maxlength) {
/* We're not allowed to add anything anymore */
@@ -1333,7 +1377,24 @@ MenuResult menuitem_process_input_ip (Me
item->data.ip.error_code = 0;
switch (token) {
- case MENUTOKEN_MENU:
+ case MENUTOKEN_LEFT:
+ /* The user wants to go to back a digit */
+ if (pos > 0) {
+ item->data.ip.edit_pos--;
+ if (str[item->data.ip.edit_pos] == ipinfo->sep)
+ item->data.ip.edit_pos--;
+ if (item->data.ip.edit_offs > item->data.ip.edit_pos)
+ item->data.ip.edit_offs = item->data.ip.edit_pos;
+#ifndef HKEY //hybrid key left
+ if( hybrid_left_key ) return MENURESULT_NONE;
+ }
+ if( !hybrid_left_key ) return MENURESULT_NONE;
+ /* fall through to MENU */
+#else
+ }
+ return MENURESULT_NONE;
+#endif /*HKEY*/
+ case MENUTOKEN_MENU:
if (pos == 0) {
return menuitem_predecessor2menuresult(
item->predecessor_id, MENURESULT_CLOSE);
@@ -1343,6 +1404,22 @@ MenuResult menuitem_process_input_ip (Me
menuitem_reset_ip(item);
}
return MENURESULT_NONE;
+ case MENUTOKEN_RIGHT:
+ if (pos < item->data.ip.maxlength - 1) {
+ item->data.ip.edit_pos++;
+ if (str[item->data.ip.edit_pos] == ipinfo->sep)
+ item->data.ip.edit_pos++;
+ while (item->data.ip.edit_pos - item->data.ip.edit_offs > display_props->width - 2)
+ item->data.ip.edit_offs++;
+#ifndef HKEY //hybrid key right
+ if( hybrid_right_key ) return MENURESULT_NONE;
+ }
+ if( !hybrid_right_key ) return MENURESULT_NONE;
+ /* fall through to ENTER */
+#else
+ }
+ return MENURESULT_NONE;
+#endif /*HKEY*/
case MENUTOKEN_ENTER:
if (extended || (pos >= item->data.ip.maxlength - 1)) {
// remove the leading spaces/zeros in each octet-representing string
@@ -1409,25 +1486,6 @@ MenuResult menuitem_process_input_ip (Me
snprintf(numstr, 5, ipinfo->format, num);
memcpy(&str[pos - (pos % (ipinfo->width + 1))], numstr, ipinfo->width);
return MENURESULT_NONE;
- case MENUTOKEN_RIGHT:
- if (pos < item->data.ip.maxlength - 1) {
- item->data.ip.edit_pos++;
- if (str[item->data.ip.edit_pos] == ipinfo->sep)
- item->data.ip.edit_pos++;
- while (item->data.ip.edit_pos - item->data.ip.edit_offs > display_props->width - 2)
- item->data.ip.edit_offs++;
- }
- return MENURESULT_NONE;
- case MENUTOKEN_LEFT:
- /* The user wants to go to back a digit */
- if (pos > 0) {
- item->data.ip.edit_pos--;
- if (str[item->data.ip.edit_pos] == ipinfo->sep)
- item->data.ip.edit_pos--;
- if (item->data.ip.edit_offs > item->data.ip.edit_pos)
- item->data.ip.edit_offs = item->data.ip.edit_pos;
- }
- return MENURESULT_NONE;
case MENUTOKEN_OTHER:
/* process other keys */
if ((strlen(key) == 1) &&
diff --exclude='*.wanjet' --exclude='.??*' --exclude=config.h --exclude='*.orig' --exclude=Makefile --exclude='*.o' --exclude=Doxyfile --exclude='*.a' --exclude=config.log --exclude=config.status --exclude='init-*' -Nuarp server/menuscreens.c server.HKEY/menuscreens.c
--- server/menuscreens.c 2006-01-26 19:47:59.000000000 -0800
+++ server.HKEY/menuscreens.c 2006-02-21 09:33:21.000000000 -0800
@@ -48,6 +48,15 @@ char * down_key;
char * left_key;
char * right_key;
+#ifndef HKEY //hybrid keys
+/*
+ * hybrid left becomes menu key at left edge of screen
+ * hybrid right becomes enter key at right edge of screen
+ */
+int hybrid_left_key = 0;
+int hybrid_right_key = 0;
+#endif //HKEY
+
Screen * menuscreen = NULL;
MenuItem * active_menuitem = NULL;
/** the "real" main_menu */
@@ -91,6 +100,11 @@ int menuscreens_init()
if (tmp)
right_key = strdup(tmp);
+#ifndef HKEY //get hybrid keys from config file
+ hybrid_right_key = config_get_bool ("menu", "HybridRightKey", 0, 0);
+ hybrid_left_key = config_get_bool ("menu", "HybridLeftKey", 0, 0);
+#endif
+
/* Now reserve keys */
input_reserve_key (menu_key, true, NULL);
@@ -186,6 +200,11 @@ void menuscreen_inform_item_modified (Me
bool is_menu_key (char * key)
{
+#ifndef HKEY //hybrid keys, any key wake-up menus
+ /* any key wakes up menus */
+ if (key && ( hybrid_left_key || hybrid_right_key ))
+ return true;
+#endif //HKEY
if (menu_key && key && strcmp (key, menu_key) == 0)
return true;
else
@@ -466,28 +485,28 @@ void menuscreen_create_menu ()
menu_add_item (options_menu, driver_menu);
if (contrast_avail) {
int contrast = driver->get_contrast(driver);
-
+
/* menu's client is NULL since we're in the server */
slider = menuitem_create_slider ("contrast", contrast_handler, "Contrast",
- NULL, "min", "max", 0, 1000, 25, contrast);
+ NULL, "min", "max", 0, 1000, 25, contrast);
menu_add_item (driver_menu, slider);
}
if (brightness_avail) {
int onbrightness = driver->get_brightness (driver, BACKLIGHT_ON);
int offbrightness = driver->get_brightness (driver, BACKLIGHT_OFF);
-
+
slider = menuitem_create_slider ("onbrightness", brightness_handler, "On Brightness",
- NULL, "min", "max", 0, 1000, 25, onbrightness);
+ NULL, "min", "max", 0, 1000, 25, onbrightness);
menu_add_item (driver_menu, slider);
slider = menuitem_create_slider ("offbrightness", brightness_handler, "Off Brightness",
- NULL, "min", "max", 0, 1000, 25, offbrightness);
+ NULL, "min", "max", 0, 1000, 25, offbrightness);
menu_add_item (driver_menu, slider);
}
}
}
-#ifdef LCDPROC_TESTMENUS
+#ifdef LCDPROC_TESTMENUS
test_menu = menu_create ("test", NULL, "Test menu", NULL);
menu_add_item (main_menu, test_menu);
+243
View File
@@ -0,0 +1,243 @@
diff --exclude='*.wanjet' --exclude='.??*' --exclude=config.h --exclude='*.orig' --exclude=Makefile --exclude='*.o' --exclude=Doxyfile --exclude='*.a' --exclude=config.log --exclude=config.status --exclude='init-*' -Nuarp server/drivers/CFontz633.c server.OPT/drivers/CFontz633.c
--- server/drivers/CFontz633.c 2006-01-26 19:47:59.000000000 -0800
+++ server.OPT/drivers/CFontz633.c 2006-02-21 19:35:27.000000000 -0800
@@ -131,6 +131,9 @@ static void CFontz633_init_vbar (Driver
static void CFontz633_init_hbar (Driver *drvthis);
static void CFontz633_no_live_report (Driver *drvthis);
static void CFontz633_hardware_clear (Driver *drvthis);
+#ifndef OPT //store boot screen
+static void CFontz633_store_boot_state (Driver *drvthis);
+#endif //OPT
/*
@@ -305,6 +308,16 @@ CFontz633_init (Driver *drvthis)
CFontz633_no_live_report (drvthis);
CFontz633_hardware_clear (drvthis);
+#ifndef OPT //store boot screen
+ /* get and store the power on boot line, repurposing the "size" buffer */
+ strncpy(size, drvthis->config_get_string (drvthis->name, "BootDisplay", 0, "" ), sizeof(size));
+ if ( size[0] ) {
+ CFontz633_string (drvthis, 1, 1, size);
+ CFontz633_flush (drvthis);
+ CFontz633_store_boot_state (drvthis);
+ }
+#endif //OPT
+
report (RPT_DEBUG, "%s: done\n", __FUNCTION__);
return 0;
@@ -1118,3 +1131,15 @@ CFontz633_string (Driver *drvthis, int x
}
}
+#ifndef OPT //store boot screen
+/*
+ * Saves current state as boot state
+ */
+static void
+CFontz633_store_boot_state (Driver *drvthis)
+{
+ PrivateData *p = drvthis->private_data;
+
+ send_zerobyte_message(p->fd, CF633_Store_Current_State_As_Boot_State);
+}
+#endif //OPT
diff --exclude='*.wanjet' --exclude='.??*' --exclude=config.h --exclude='*.orig' --exclude=Makefile --exclude='*.o' --exclude=Doxyfile --exclude='*.a' --exclude=config.log --exclude=config.status --exclude='init-*' -Nuarp server/menuscreens.c server.OPT/menuscreens.c
--- server/menuscreens.c 2006-01-26 19:47:59.000000000 -0800
+++ server.OPT/menuscreens.c 2006-02-21 19:31:00.000000000 -0800
@@ -48,6 +48,9 @@ char * down_key;
char * left_key;
char * right_key;
+#ifndef OPT
+char * menuname; /* the name for the default menu */
+#endif //OPT
Screen * menuscreen = NULL;
MenuItem * active_menuitem = NULL;
/** the "real" main_menu */
@@ -91,6 +94,11 @@ int menuscreens_init()
if (tmp)
right_key = strdup(tmp);
+#ifndef OPT //get main menu name and hybrid keys from config file
+ /* Get main menu name from config file */
+ menuname = strdup (config_get_string ("menu", "menuname", 0, "LCDproc Menu"));
+#endif //OPT
+
/* Now reserve keys */
input_reserve_key (menu_key, true, NULL);
@@ -437,55 +445,62 @@ void menuscreen_create_menu ()
debug (RPT_DEBUG, "%s()", __FUNCTION__);
+#ifndef OPT //main menu name from config file
+ main_menu = menu_create ("mainmenu", NULL, menuname, NULL);
+#else //OPT
main_menu = menu_create ("mainmenu", NULL, "LCDproc Menu", NULL);
+#endif //OPT
- options_menu = menu_create ("options", NULL, "Options", NULL);
- menu_add_item (main_menu, options_menu);
-
-#ifdef LCDPROC_TESTMENUS
- screens_menu = menu_create ("screens", NULL, "Screens", NULL);
- menu_add_item (main_menu, screens_menu);
-#endif /*LCDPROC_TESTMENUS*/
-
- /* menu's client is NULL since we're in the server */
- checkbox = menuitem_create_checkbox ("heartbeat", heartbeat_handler, "Heartbeat", NULL, true, heartbeat);
- menu_add_item (options_menu, checkbox);
-
- /* menu's client is NULL since we're in the server */
- checkbox = menuitem_create_checkbox ("backlight", backlight_handler, "Backlight", NULL, true, backlight);
- menu_add_item (options_menu, checkbox);
+#ifndef OPT //Options menu display from config file
+ if ( config_get_bool ("server", "LCDOptionsMenu", 0, 0)) {
+ options_menu = menu_create ("options", NULL, "Options", NULL);
+ menu_add_item (main_menu, options_menu);
+
+ /* menu's client is NULL since we're in the server */
+ checkbox = menuitem_create_checkbox ("heartbeat", heartbeat_handler, "Heartbeat", NULL, true, heartbeat);
+ menu_add_item (options_menu, checkbox);
+
+ /* menu's client is NULL since we're in the server */
+ checkbox = menuitem_create_checkbox ("backlight", backlight_handler, "Backlight", NULL, true, backlight);
+ menu_add_item (options_menu, checkbox);
+
+ for (driver = drivers_getfirst(); driver; driver = drivers_getnext()) {
+ int contrast_avail = (driver->get_contrast && driver->set_contrast) ? 1 : 0;
+ int brightness_avail = (driver->get_brightness && driver->set_brightness) ? 1 : 0;
- for (driver = drivers_getfirst(); driver; driver = drivers_getnext()) {
- int contrast_avail = (driver->get_contrast && driver->set_contrast) ? 1 : 0;
- int brightness_avail = (driver->get_brightness && driver->set_brightness) ? 1 : 0;
-
- if (contrast_avail || brightness_avail) {
- /* menu's client is NULL since we're in the server */
- driver_menu = menu_create (driver->name, NULL, driver->name, NULL);
- menu_set_association(driver_menu, driver);
- menu_add_item (options_menu, driver_menu);
- if (contrast_avail) {
- int contrast = driver->get_contrast(driver);
-
+ if (contrast_avail || brightness_avail) {
/* menu's client is NULL since we're in the server */
- slider = menuitem_create_slider ("contrast", contrast_handler, "Contrast",
- NULL, "min", "max", 0, 1000, 25, contrast);
- menu_add_item (driver_menu, slider);
- }
- if (brightness_avail) {
- int onbrightness = driver->get_brightness (driver, BACKLIGHT_ON);
- int offbrightness = driver->get_brightness (driver, BACKLIGHT_OFF);
-
- slider = menuitem_create_slider ("onbrightness", brightness_handler, "On Brightness",
- NULL, "min", "max", 0, 1000, 25, onbrightness);
- menu_add_item (driver_menu, slider);
-
- slider = menuitem_create_slider ("offbrightness", brightness_handler, "Off Brightness",
- NULL, "min", "max", 0, 1000, 25, offbrightness);
- menu_add_item (driver_menu, slider);
+ driver_menu = menu_create (driver->name, NULL, driver->name, NULL);
+ menu_set_association(driver_menu, driver);
+ menu_add_item (options_menu, driver_menu);
+ if (contrast_avail) {
+ int contrast = driver->get_contrast(driver);
+
+ /* menu's client is NULL since we're in the server */
+ slider = menuitem_create_slider ("contrast", contrast_handler, "Contrast",
+ NULL, "min", "max", 0, 1000, 25, contrast);
+ menu_add_item (driver_menu, slider);
+ }
+ if (brightness_avail) {
+ int onbrightness = driver->get_brightness (driver, BACKLIGHT_ON);
+ int offbrightness = driver->get_brightness (driver, BACKLIGHT_OFF);
+
+ slider = menuitem_create_slider ("onbrightness", brightness_handler, "On Brightness",
+ NULL, "min", "max", 0, 1000, 25, onbrightness);
+ menu_add_item (driver_menu, slider);
+
+ slider = menuitem_create_slider ("offbrightness", brightness_handler, "Off Brightness",
+ NULL, "min", "max", 0, 1000, 25, offbrightness);
+ menu_add_item (driver_menu, slider);
+ }
}
}
}
+ if ( config_get_bool ("server", "LCDScreensMenu", 0, 0)) {
+ screens_menu = menu_create ("screens", NULL, "Screens", NULL);
+ menu_add_item (main_menu, screens_menu);
+ }
+#endif //OPT
#ifdef LCDPROC_TESTMENUS
test_menu = menu_create ("test", NULL, "Test menu", NULL);
diff --exclude='*.wanjet' --exclude='.??*' --exclude=config.h --exclude='*.orig' --exclude=Makefile --exclude='*.o' --exclude=Doxyfile --exclude='*.a' --exclude=config.log --exclude=config.status --exclude='init-*' -Nuarp server/serverscreens.c server.OPT/serverscreens.c
--- server/serverscreens.c 2006-01-26 19:47:59.000000000 -0800
+++ server.OPT/serverscreens.c 2006-02-21 19:27:40.000000000 -0800
@@ -31,6 +31,12 @@
#include "widget.h"
#include "serverscreens.h"
+#ifndef OPT //startup screen title from config
+#include "shared/configfile.h"
+
+char * title;
+#endif //OPT
+
#define UNSET_INT -1
Screen * server_screen;
@@ -38,6 +44,7 @@ int rotate_server_screen = UNSET_INT;
#define MAX_SERVERSCREEN_WIDTH 40
+
int
server_screen_init ()
{
@@ -46,6 +53,11 @@ server_screen_init ()
debug (RPT_DEBUG, "server_screen_init");
+#ifndef OPT //startup screen title from config
+ /* Get server title name from config file */
+ title = strdup (config_get_string ("server", "title", 0, "LCDproc Server"));
+#endif //OPT
+
/* Create the screen */
server_screen = screen_create ("_server_screen", NULL);
if (!server_screen) {
@@ -77,7 +89,11 @@ server_screen_init ()
w->text = malloc (MAX_SERVERSCREEN_WIDTH+1);
if (line == 1) {
w->type = WID_TITLE;
+#ifndef OPT //startup screen titel from config
+ strncpy (w->text, title, MAX_SERVERSCREEN_WIDTH);
+#else //OPT
strncpy (w->text, "LCDproc Server", MAX_SERVERSCREEN_WIDTH);
+#endif //OPT
} else {
w->text[0] = 0;
}
@@ -156,6 +172,18 @@ goodbye_screen ()
char *l16 = " LCDproc! ";
#endif
+#ifndef OPT // disable config goobye
+ char * goodbye_string;
+
+ if ( (goodbye_string = strdup(config_get_string("server", "goodbye", 0, "")))) {
+ t20=t16=goodbye_string;
+ if (strlen(goodbye_string) > 16 )
+ l16 = goodbye_string + 16;
+ if (strlen(goodbye_string) > 20 )
+ l20 = goodbye_string + 20;
+ }
+#endif //OPT
+
if( !display_props )
return 0;
File diff suppressed because it is too large Load Diff
+21
View File
@@ -0,0 +1,21 @@
CFLAGS=-Wall -g -MD
LDFLAGS=
CC=gcc
TARGET = if_demo
MEMBERS=${TARGET} lib-myconnect lib-mylcd interface af sockets nstrcmp util hw unix inet loopback ether tunnel ppp frame arcnet
DEPS = $(patsubst %,%.d,$(MEMBERS))
OBJECTS = $(patsubst %,%.o,$(MEMBERS))
all: ${TARGET}
${TARGET}: ${OBJECTS}
${CC} -o ${TARGET} ${OBJECTS} ${CFLAGS} ${LDFLAGS}
clean:
rm *.o *.d ${TARGET}
-include ${DEPS}
+16
View File
@@ -0,0 +1,16 @@
From: Thomas Riewe <thomas.riewe@pyramid.de>
may be someone else will find our little testing setup also helpful ?!
i attached it to this mail (since it's just 28K though i didn't clean up the files ...)
and one can download it from
http://www.pyramid.de/e/produkte/server/pyramid-lcd.php#step_by_step
respectively
http://www.pyramid.de/d/downloads/demo_for_pylcd-lcdproc.tgz
AFAIK it will be quite easy to adapt it to other LCDs
HTH & keep up the good work
regards,
thomas
+345
View File
@@ -0,0 +1,345 @@
/*
* lib/af.c This file contains the top-level part of the protocol
* support functions module for the NET-2 base distribution.
*
* Version: $Id$
*
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
* Copyright 1993 MicroWalt Corporation
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at
* your option) any later version.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include "config.h"
#include "net-support.h"
#include "pathnames.h"
#include "intl.h"
#include "util.h"
int flag_unx;
int flag_ipx;
int flag_ax25;
int flag_ddp;
int flag_netrom;
int flag_inet;
int flag_inet6;
int flag_econet;
int flag_x25 = 0;
int flag_ash;
struct aftrans_t {
char *alias;
char *name;
int *flag;
} aftrans[] = {
{
"ax25", "ax25", &flag_ax25
},
{
"ip", "inet", &flag_inet
},
{
"ip6", "inet6", &flag_inet6
},
{
"ipx", "ipx", &flag_ipx
},
{
"appletalk", "ddp", &flag_ddp
},
{
"netrom", "netrom", &flag_netrom
},
{
"inet", "inet", &flag_inet
},
{
"inet6", "inet6", &flag_inet6
},
{
"ddp", "ddp", &flag_ddp
},
{
"unix", "unix", &flag_unx
},
{
"tcpip", "inet", &flag_inet
},
{
"econet", "ec", &flag_econet
},
{
"x25", "x25", &flag_x25
},
{
"ash", "ash", &flag_ash
},
{
0, 0, 0
}
};
char afname[256] = "";
extern struct aftype unspec_aftype;
extern struct aftype unix_aftype;
extern struct aftype inet_aftype;
extern struct aftype inet6_aftype;
extern struct aftype ax25_aftype;
extern struct aftype netrom_aftype;
extern struct aftype ipx_aftype;
extern struct aftype ddp_aftype;
extern struct aftype ec_aftype;
extern struct aftype x25_aftype;
extern struct aftype rose_aftype;
extern struct aftype ash_aftype;
static short sVafinit = 0;
struct aftype *aftypes[] =
{
#if HAVE_AFUNIX
&unix_aftype,
#endif
#if HAVE_AFINET
&inet_aftype,
#endif
#if HAVE_AFINET6
&inet6_aftype,
#endif
#if HAVE_AFAX25
&ax25_aftype,
#endif
#if HAVE_AFNETROM
&netrom_aftype,
#endif
#if HAVE_AFROSE
&rose_aftype,
#endif
#if HAVE_AFIPX
&ipx_aftype,
#endif
#if HAVE_AFATALK
&ddp_aftype,
#endif
#if HAVE_AFECONET
&ec_aftype,
#endif
#if HAVE_AFASH
&ash_aftype,
#endif
#if HAVE_AFX25
&x25_aftype,
#endif
&unspec_aftype,
NULL
};
void afinit()
{
unspec_aftype.title = _("UNSPEC");
#if HAVE_AFUNIX
unix_aftype.title = _("UNIX Domain");
#endif
#if HAVE_AFINET
inet_aftype.title = _("DARPA Internet");
#endif
#if HAVE_AFINET6
inet6_aftype.title = _("IPv6");
#endif
#if HAVE_AFAX25
ax25_aftype.title = _("AMPR AX.25");
#endif
#if HAVE_AFNETROM
netrom_aftype.title = _("AMPR NET/ROM");
#endif
#if HAVE_AFIPX
ipx_aftype.title = _("Novell IPX");
#endif
#if HAVE_AFATALK
ddp_aftype.title = _("Appletalk DDP");
#endif
#if HAVE_AFECONET
ec_aftype.title = _("Econet");
#endif
#if HAVE_AFX25
x25_aftype.title = _("CCITT X.25");
#endif
#if HAVE_AFROSE
rose_aftype.title = _("AMPR ROSE");
#endif
#if HAVE_AFASH
ash_aftype.title = _("Ash");
#endif
sVafinit = 1;
}
/* set the default AF list from the program name or a constant value */
void aftrans_def(char *tool, char *argv0, char *dflt)
{
char *tmp;
char *buf;
strcpy(afname, dflt);
if (!(tmp = strrchr(argv0, '/')))
tmp = argv0; /* no slash?! */
else
tmp++;
if (!(buf = strdup(tmp)))
return;
if (strlen(tool) >= strlen(tmp)) {
free(buf);
return;
}
tmp = buf + (strlen(tmp) - strlen(tool));
if (strcmp(tmp, tool) != 0) {
free(buf);
return;
}
*tmp = '\0';
if ((tmp = strchr(buf, '_')))
*tmp = '\0';
afname[0] = '\0';
if (aftrans_opt(buf))
strcpy(afname, buf);
free(buf);
}
/* Check our protocol family table for this family. */
struct aftype *get_aftype(const char *name)
{
struct aftype **afp;
if (!sVafinit)
afinit();
afp = aftypes;
while (*afp != NULL) {
if (!strcmp((*afp)->name, name))
return (*afp);
afp++;
}
if (index(name, ','))
fprintf(stderr, _("Please don't supply more than one address family.\n"));
return (NULL);
}
/* Check our protocol family table for this family. */
struct aftype *get_afntype(int af)
{
struct aftype **afp;
if (!sVafinit)
afinit();
afp = aftypes;
while (*afp != NULL) {
if ((*afp)->af == af)
return (*afp);
afp++;
}
return (NULL);
}
/* Check our protocol family table for this family and return its socket */
int get_socket_for_af(int af)
{
struct aftype **afp;
if (!sVafinit)
afinit();
afp = aftypes;
while (*afp != NULL) {
if ((*afp)->af == af)
return (*afp)->fd;
afp++;
}
return -1;
}
int aftrans_opt(const char *arg)
{
struct aftrans_t *paft;
char *tmp1, *tmp2;
char buf[256];
safe_strncpy(buf, arg, sizeof(buf));
tmp1 = buf;
while (tmp1) {
tmp2 = index(tmp1, ',');
if (tmp2)
*(tmp2++) = '\0';
paft = aftrans;
for (paft = aftrans; paft->alias; paft++) {
if (strcmp(tmp1, paft->alias))
continue;
if (strlen(paft->name) + strlen(afname) + 1 >= sizeof(afname)) {
fprintf(stderr, _("Too much address family arguments.\n"));
return (0);
}
if (paft->flag)
(*paft->flag)++;
if (afname[0])
strcat(afname, ",");
strcat(afname, paft->name);
break;
}
if (!paft->alias) {
fprintf(stderr, _("Unknown address family `%s'.\n"), tmp1);
return (1);
}
tmp1 = tmp2;
}
return (0);
}
/* type: 0=all, 1=getroute */
void print_aflist(int type) {
int count = 0;
char * txt;
struct aftype **afp;
if (!sVafinit)
afinit();
afp = aftypes;
while (*afp != NULL) {
if ((type == 1 && ((*afp)->rprint == NULL)) || ((*afp)->af == 0)) {
afp++; continue;
}
if ((count % 3) == 0) fprintf(stderr,count?"\n ":" ");
txt = (*afp)->name; if (!txt) txt = "..";
fprintf(stderr,"%s (%s) ",txt,(*afp)->title);
count++;
afp++;
}
fprintf(stderr,"\n");
}
+129
View File
@@ -0,0 +1,129 @@
/*
* lib/arcnet.c This file contains an implementation of the "ARCnet"
* support functions for the NET-2 base distribution.
*
* Version: $Id$
*
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
* Copyright 1993 MicroWalt Corporation
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at
* your option) any later version.
*/
#include "config.h"
#if HAVE_HWARC
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if_arp.h>
#include <linux/if_ether.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include "net-support.h"
#include "pathnames.h"
#include "intl.h"
#include "util.h"
extern struct hwtype arcnet_hwtype;
/* Display an ARCnet address in readable format. */
static char *pr_arcnet(unsigned char *ptr)
{
static char buff[64];
snprintf(buff, sizeof(buff), "%02X", (ptr[0] & 0377));
return (buff);
}
/* Input an ARCnet address and convert to binary. */
static int in_arcnet(char *bufp, struct sockaddr *sap)
{
unsigned char *ptr;
char c, *orig;
int i, val;
sap->sa_family = arcnet_hwtype.type;
ptr = sap->sa_data;
i = 0;
orig = bufp;
while ((*bufp != '\0') && (i < 1)) {
val = 0;
c = *bufp++;
if (isdigit(c))
val = c - '0';
else if (c >= 'a' && c <= 'f')
val = c - 'a' + 10;
else if (c >= 'A' && c <= 'F')
val = c - 'A' + 10;
else {
#ifdef DEBUG
fprintf(stderr, _("in_arcnet(%s): invalid arcnet address!\n"), orig);
#endif
errno = EINVAL;
return (-1);
}
val <<= 4;
c = *bufp++;
if (isdigit(c))
val |= c - '0';
else if (c >= 'a' && c <= 'f')
val |= c - 'a' + 10;
else if (c >= 'A' && c <= 'F')
val |= c - 'A' + 10;
else {
#ifdef DEBUG
fprintf(stderr, _("in_arcnet(%s): invalid arcnet address!\n"), orig);
#endif
errno = EINVAL;
return (-1);
}
*ptr++ = (unsigned char) (val & 0377);
i++;
/* We might get a semicolon here - not required. */
if (*bufp == ':') {
if (i == ETH_ALEN) {
#ifdef DEBUG
fprintf(stderr, _("in_arcnet(%s): trailing : ignored!\n"),
orig)
#endif
; /* nothing */
}
bufp++;
}
}
/* That's it. Any trailing junk? */
if ((i == ETH_ALEN) && (*bufp != '\0')) {
#ifdef DEBUG
fprintf(stderr, _("in_arcnet(%s): trailing junk!\n"), orig);
errno = EINVAL;
return (-1);
#endif
}
#ifdef DEBUG
fprintf(stderr, "in_arcnet(%s): %s\n", orig, pr_arcnet(sap->sa_data));
#endif
return (0);
}
struct hwtype arcnet_hwtype =
{
"arcnet", NULL, /*"2.5Mbps ARCnet", */ ARPHRD_ARCNET, 1,
pr_arcnet, in_arcnet, NULL
};
#endif /* HAVE_HWARC */
+76
View File
@@ -0,0 +1,76 @@
/*
* config.h Automatically generated configuration includefile
*
* NET-TOOLS A collection of programs that form the base set of the
* NET-3 Networking Distribution for the LINUX operating
* system.
*
* DO NOT EDIT DIRECTLY
*
*/
/*
*
* Internationalization
*
* The net-tools package has currently been translated to French,
* German and Brazilian Portugese. Other translations are, of
* course, welcome. Answer `n' here if you have no support for
* internationalization on your system.
*
*/
#define I18N 0
/*
*
* Protocol Families.
*
*/
#define HAVE_AFUNIX 1
#define HAVE_AFINET 1
#define HAVE_AFINET6 0
#define HAVE_AFIPX 0
#define HAVE_AFATALK 0
#define HAVE_AFAX25 0
#define HAVE_AFNETROM 0
#define HAVE_AFROSE 0
#define HAVE_AFX25 0
#define HAVE_AFECONET 0
#define HAVE_AFDECnet 0
#define HAVE_AFASH 0
/*
*
* Device Hardware types.
*
*/
#define HAVE_HWETHER 1
#define HAVE_HWARC 1
#define HAVE_HWSLIP 0
#define HAVE_HWPPP 1
#define HAVE_HWTUNNEL 1
#define HAVE_HWSTRIP 0
#define HAVE_HWTR 0
#define HAVE_HWAX25 0
#define HAVE_HWROSE 0
#define HAVE_HWNETROM 0
#define HAVE_HWX25 0
#define HAVE_HWFR 1
#define HAVE_HWSIT 0
#define HAVE_HWFDDI 0
#define HAVE_HWHIPPI 0
#define HAVE_HWASH 0
#define HAVE_HWHDLCLAPB 0
#define HAVE_HWIRDA 0
#define HAVE_HWEC 0
#define HAVE_HWEUI64 0
/*
*
* Other Features.
*
*/
#define HAVE_FW_MASQUERADE 0
#define HAVE_IP_TOOLS 0
#define HAVE_MII 0
+137
View File
@@ -0,0 +1,137 @@
/*
* lib/ether.c This file contains an implementation of the "Ethernet"
* support functions.
*
* Version: $Id$
*
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
* Copyright 1993 MicroWalt Corporation
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at
* your option) any later version.
*/
#include "config.h"
#if HAVE_HWETHER
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if_arp.h>
#include <linux/if_ether.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include "net-support.h"
#include "pathnames.h"
#include "intl.h"
#include "util.h"
extern struct hwtype ether_hwtype;
/* Display an Ethernet address in readable format. */
static char *pr_ether(unsigned char *ptr)
{
static char buff[64];
snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X",
(ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
(ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
);
return (buff);
}
/* Input an Ethernet address and convert to binary. */
static int in_ether(char *bufp, struct sockaddr *sap)
{
unsigned char *ptr;
char c, *orig;
int i;
unsigned val;
sap->sa_family = ether_hwtype.type;
ptr = sap->sa_data;
i = 0;
orig = bufp;
while ((*bufp != '\0') && (i < ETH_ALEN)) {
val = 0;
c = *bufp++;
if (isdigit(c))
val = c - '0';
else if (c >= 'a' && c <= 'f')
val = c - 'a' + 10;
else if (c >= 'A' && c <= 'F')
val = c - 'A' + 10;
else {
#ifdef DEBUG
fprintf(stderr, _("in_ether(%s): invalid ether address!\n"), orig);
#endif
errno = EINVAL;
return (-1);
}
val <<= 4;
c = *bufp;
if (isdigit(c))
val |= c - '0';
else if (c >= 'a' && c <= 'f')
val |= c - 'a' + 10;
else if (c >= 'A' && c <= 'F')
val |= c - 'A' + 10;
else if (c == ':' || c == 0)
val >>= 4;
else {
#ifdef DEBUG
fprintf(stderr, _("in_ether(%s): invalid ether address!\n"), orig);
#endif
errno = EINVAL;
return (-1);
}
if (c != 0)
bufp++;
*ptr++ = (unsigned char) (val & 0377);
i++;
/* We might get a semicolon here - not required. */
if (*bufp == ':') {
if (i == ETH_ALEN) {
#ifdef DEBUG
fprintf(stderr, _("in_ether(%s): trailing : ignored!\n"),
orig)
#endif
; /* nothing */
}
bufp++;
}
}
/* That's it. Any trailing junk? */
if ((i == ETH_ALEN) && (*bufp != '\0')) {
#ifdef DEBUG
fprintf(stderr, _("in_ether(%s): trailing junk!\n"), orig);
errno = EINVAL;
return (-1);
#endif
}
#ifdef DEBUG
fprintf(stderr, "in_ether(%s): %s\n", orig, pr_ether(sap->sa_data));
#endif
return (0);
}
struct hwtype ether_hwtype =
{
"ether", NULL, /*"10Mbps Ethernet", */ ARPHRD_ETHER, ETH_ALEN,
pr_ether, in_ether, NULL
};
#endif /* HAVE_HWETHER */
+59
View File
@@ -0,0 +1,59 @@
/*
* lib/frame.c This file contains the Frame Relay support.
*
* Version: $Id$
*
* Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de>
*
* Author: Mike McLagan <mike.mclagan@linux.org>
*
* Changes:
*
*962303 {0.01} Mike McLagan : creation
*960413 {0.02} Bernd Eckenfels : included in net-lib
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at
* your option) any later version.
*/
#include "config.h"
#if HAVE_HWFR
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if_arp.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include "net-support.h"
#include "pathnames.h"
char *pr_dlci(unsigned char *ptr)
{
static char buf[12];
snprintf(buf, sizeof(buf), "%i", *(short *) ptr);
return (buf);
}
struct hwtype dlci_hwtype =
{
"dlci", NULL, /*"Frame Relay DLCI", */ ARPHRD_DLCI, 3,
pr_dlci, NULL, NULL, 0
};
struct hwtype frad_hwtype =
{
"frad", NULL, /*"Frame Relay Access Device", */ ARPHRD_FRAD, 0,
NULL, NULL, NULL, 0
};
#endif /* HAVE_HWFR */
+298
View File
@@ -0,0 +1,298 @@
/*
* lib/hw.c This file contains the top-level part of the hardware
* support functions module.
*
* Version: $Id$
*
* Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de>
*
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
* Copyright 1993 MicroWalt Corporation
*
*980701 {1.21} Arnaldo C. Melo GNU gettext instead of catgets
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at
* your option) any later version.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if_arp.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include "config.h"
#include "net-support.h"
#include "pathnames.h"
#include "intl.h"
extern struct hwtype unspec_hwtype;
extern struct hwtype loop_hwtype;
extern struct hwtype slip_hwtype;
extern struct hwtype cslip_hwtype;
extern struct hwtype slip6_hwtype;
extern struct hwtype cslip6_hwtype;
extern struct hwtype adaptive_hwtype;
extern struct hwtype strip_hwtype;
extern struct hwtype ether_hwtype;
extern struct hwtype fddi_hwtype;
extern struct hwtype hippi_hwtype;
extern struct hwtype tr_hwtype;
#ifdef ARPHRD_IEEE802_TR
extern struct hwtype tr_hwtype1;
#endif
extern struct hwtype ax25_hwtype;
extern struct hwtype rose_hwtype;
extern struct hwtype netrom_hwtype;
extern struct hwtype x25_hwtype;
extern struct hwtype tunnel_hwtype;
extern struct hwtype ash_hwtype;
extern struct hwtype ppp_hwtype;
extern struct hwtype arcnet_hwtype;
extern struct hwtype dlci_hwtype;
extern struct hwtype frad_hwtype;
extern struct hwtype hdlc_hwtype;
extern struct hwtype lapb_hwtype;
extern struct hwtype sit_hwtype;
extern struct hwtype irda_hwtype;
extern struct hwtype ec_hwtype;
extern struct hwtype eui64_hwtype;
static struct hwtype *hwtypes[] =
{
&loop_hwtype,
#if HAVE_HWSLIP
&slip_hwtype,
&cslip_hwtype,
&slip6_hwtype,
&cslip6_hwtype,
&adaptive_hwtype,
#endif
#if HAVE_HWSTRIP
&strip_hwtype,
#endif
#if HAVE_HWASH
&ash_hwtype,
#endif
#if HAVE_HWETHER
&ether_hwtype,
#endif
#if HAVE_HWTR
&tr_hwtype,
#ifdef ARPHRD_IEEE802_TR
&tr_hwtype1,
#endif
#endif
#if HAVE_HWAX25
&ax25_hwtype,
#endif
#if HAVE_HWNETROM
&netrom_hwtype,
#endif
#if HAVE_HWROSE
&rose_hwtype,
#endif
#if HAVE_HWTUNNEL
&tunnel_hwtype,
#endif
#if HAVE_HWPPP
&ppp_hwtype,
#endif
#if HAVE_HWHDLCLAPB
&hdlc_hwtype,
&lapb_hwtype,
#endif
#if HAVE_HWARC
&arcnet_hwtype,
#endif
#if HAVE_HWFR
&dlci_hwtype,
&frad_hwtype,
#endif
#if HAVE_HWSIT
&sit_hwtype,
#endif
#if HAVE_HWFDDI
&fddi_hwtype,
#endif
#if HAVE_HWHIPPI
&hippi_hwtype,
#endif
#if HAVE_HWIRDA
&irda_hwtype,
#endif
#if HAVE_HWEC
&ec_hwtype,
#endif
#if HAVE_HWX25
&x25_hwtype,
#endif
#if HAVE_HWEUI64
&eui64_hwtype,
#endif
&unspec_hwtype,
NULL
};
static short sVhwinit = 0;
void hwinit()
{
loop_hwtype.title = _("Local Loopback");
unspec_hwtype.title = _("UNSPEC");
#if HAVE_HWSLIP
slip_hwtype.title = _("Serial Line IP");
cslip_hwtype.title = _("VJ Serial Line IP");
slip6_hwtype.title = _("6-bit Serial Line IP");
cslip6_hwtype.title = _("VJ 6-bit Serial Line IP");
adaptive_hwtype.title = _("Adaptive Serial Line IP");
#endif
#if HAVE_HWETHER
ether_hwtype.title = _("Ethernet");
#endif
#if HAVE_HWASH
ash_hwtype.title = _("Ash");
#endif
#if HAVE_HWFDDI
fddi_hwtype.title = _("Fiber Distributed Data Interface");
#endif
#if HAVE_HWHIPPI
hippi_hwtype.title = _("HIPPI");
#endif
#if HAVE_HWAX25
ax25_hwtype.title = _("AMPR AX.25");
#endif
#if HAVE_HWROSE
rose_hwtype.title = _("AMPR ROSE");
#endif
#if HAVE_HWNETROM
netrom_hwtype.title = _("AMPR NET/ROM");
#endif
#if HAVE_HWX25
x25_hwtype.title = _("generic X.25");
#endif
#if HAVE_HWTUNNEL
tunnel_hwtype.title = _("IPIP Tunnel");
#endif
#if HAVE_HWPPP
ppp_hwtype.title = _("Point-to-Point Protocol");
#endif
#if HAVE_HWHDLCLAPB
hdlc_hwtype.title = _("(Cisco)-HDLC");
lapb_hwtype.title = _("LAPB");
#endif
#if HAVE_HWARC
arcnet_hwtype.title = _("ARCnet");
#endif
#if HAVE_HWFR
dlci_hwtype.title = _("Frame Relay DLCI");
frad_hwtype.title = _("Frame Relay Access Device");
#endif
#if HAVE_HWSIT
sit_hwtype.title = _("IPv6-in-IPv4");
#endif
#if HAVE_HWIRDA
irda_hwtype.title = _("IrLAP");
#endif
#if HAVE_HWTR
tr_hwtype.title = _("16/4 Mbps Token Ring");
#ifdef ARPHRD_IEEE802_TR
tr_hwtype1.title = _("16/4 Mbps Token Ring (New)") ;
#endif
#endif
#if HAVE_HWEC
ec_hwtype.title = _("Econet");
#endif
#if HAVE_HWEUI64
eui64_hwtype.title = _("Generic EUI-64");
#endif
sVhwinit = 1;
}
/* Check our hardware type table for this type. */
struct hwtype *get_hwtype(const char *name)
{
struct hwtype **hwp;
if (!sVhwinit)
hwinit();
hwp = hwtypes;
while (*hwp != NULL) {
if (!strcmp((*hwp)->name, name))
return (*hwp);
hwp++;
}
return (NULL);
}
/* Check our hardware type table for this type. */
struct hwtype *get_hwntype(int type)
{
struct hwtype **hwp;
if (!sVhwinit)
hwinit();
hwp = hwtypes;
while (*hwp != NULL) {
if ((*hwp)->type == type)
return (*hwp);
hwp++;
}
return (NULL);
}
/* type: 0=all, 1=ARPable */
void print_hwlist(int type) {
int count = 0;
char * txt;
struct hwtype **hwp;
if (!sVhwinit)
hwinit();
hwp = hwtypes;
while (*hwp != NULL) {
if (((type == 1) && ((*hwp)->alen == 0)) || ((*hwp)->type == -1)) {
hwp++; continue;
}
if ((count % 3) == 0) fprintf(stderr,count?"\n ":" ");
txt = (*hwp)->name; if (!txt) txt = "..";
fprintf(stderr,"%s (%s) ",txt,(*hwp)->title);
count++;
hwp++;
}
fprintf(stderr,"\n");
}
/* return 1 if address is all zeros */
int hw_null_address(struct hwtype *hw, void *ap)
{
unsigned int i;
unsigned char *address = (unsigned char *)ap;
for (i = 0; i < hw->alen; i++)
if (address[i])
return 0;
return 1;
}
+590
View File
@@ -0,0 +1,590 @@
/* if_demo.c
interfacedemo for pylcd device.
*/
/*
Copyright (C) 2005 Silvan Marco Fin <silvan@kernelconcepts.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
#include <netdb.h>
#include <errno.h>
#include <wait.h>
#include <net/if.h>
#include <sys/socket.h>
#include "lib-myconnect.h"
#include "lib-mylcd.h"
#include "interface.h"
#include "sockets.h"
#include "net-support.h"
#define DEBUG 0
#define SUCC_DUR 10 /* Duration in sec. how long a success-message is displayed */
/* External programs to be called. */
#define INTERFACE_SCRIPT "./scripts/MyIPSet"
#define REBOOT_SCRIPT "./scripts/MyReboot"
#define HALT_SCRIPT "./scripts/MyHalt"
/* Modes for action */
#define BLANK 0
#define UPDATE 1
#define IFSELECTED 2
#define IPCHANGED 3
#define NMCHANGED 4
#define GWCHANGED 5
#define MENULEFT 6
#define SELECT 7
struct iftype
{
char name[32];
char ip[16];
char netmask[16];
char gateway[16];
};
struct
{
unsigned int sIF;
unsigned int IFnum;
struct iftype IFdata[32];
} status;
int skfd;
void print_help()
{
printf("Usage:\n");
printf(" [-p #] specify Portnumber (defaults to 13666).\n");
printf(" -d ... specify comma separated list of devices to manage.\n");
printf("\n");
printf("Example: if_demo -d eth0,wlan0 -p 12345\n\n");
}
void init_screen(int SD)
{
char *buffer;
buffer=basic_send(SD, "hello");
buffer=basic_send(SD, "client_set -name {Managment}");
buffer=basic_send(SD, "screen_add main");
buffer=basic_send(SD, "screen_set main -name {main}");
buffer=basic_send(SD, "screen_set main -heartbeat off");
buffer=basic_send(SD, "screen_set main -priority foreground");
/* buffer=basic_send(SD, "screen_set main -duration 80"); */
/* buffer=basic_send(SD, "screen_set main -cursor on"); */
}
void alert_screen(int SD, char *line1, char *line2, int duration)
{
char *buffer;
char mesg[255];
/* buffer=basic_send(SD, "widget_del main mainscroller"); */
buffer=basic_send(SD, "screen_add info");
buffer=basic_send(SD, "screen_set info -priority alert");
sprintf(mesg, "screen_set info -timeout %d", duration);
buffer=basic_send(SD, mesg);
buffer=basic_send(SD, "widget_add info infostring1 string");
buffer=basic_send(SD, "widget_add info infostring2 string");
sprintf(mesg, "widget_set info infostring1 1 1 {%s}", line1);
buffer=basic_send(SD, mesg);
sprintf(mesg, "widget_set info infostring2 1 2 {%s}", line2);
buffer=basic_send(SD, mesg);
}
void interfaces(int SD, char *cs_iflist)
{
char *buffer;
char *retval;
char *next=cs_iflist;
char mesg[255];
unsigned int orig_len=strlen(cs_iflist);
unsigned int i=0;
/* Now we fill the interfaces to the status variable. */
while (1)
{
retval=strtok(next, ",");
next=NULL;
if (retval==NULL)
break; /* or return? */
strcpy(status.IFdata[i].name, retval);
/* If interface is up, then get it's numbers and use them, else set to default-Values */
/* Default values: */
sprintf(status.IFdata[i].ip, "000.000.000.000");
sprintf(status.IFdata[i].netmask, "255.255.255.255");
sprintf(status.IFdata[i].gateway, "000.000.000.000");
if (DEBUG)
printf("IF %s: IP=%s, NM=%s, GW=%s\n", status.IFdata[i].name, status.IFdata[i].ip, status.IFdata[i].netmask, status.IFdata[i].gateway);
sprintf(mesg, "menu_add_item SIF %d action {sel. %s} -next CHSET", i, status.IFdata[i].name);
buffer=basic_send(SD, mesg);
i++;
}
status.IFnum=i+1;
/* now prepare cs_iflist so that we can generate a menu entry. */
for (i=0; i<orig_len; i++)
if (cs_iflist[i]=='\0') cs_iflist[i]='\t';
/* sprintf(mesg, "menu_add_item SIF selection ring {IF:} -strings {%s}", cs_iflist); */ /* For use of a selection ring */
/* buffer=basic_send(SD, mesg); */
status.sIF=0;
}
void old_autointerfaces(int SD)
{
struct if_nameindex *if_list;
char buffer[1000]="";
int i;
if_list=if_nameindex();
for (i=0; if_list[i].if_name!=NULL; i++)
{
if (strcmp(if_list[i].if_name, "lo")==0)
continue;
if (strlen(buffer)==0)
sprintf(buffer, "%s", if_list[i].if_name);
else
sprintf(buffer, "%s,%s", buffer, if_list[i].if_name);
}
interfaces(SD, buffer);
}
int do_if_action(int SD, struct interface *ife, void *cookie)
{
int *opt_a = (int *) cookie;
int res;
struct aftype *ap;
static unsigned int i=0;
char mesg[255];
char *buffer;
res = do_if_fetch(ife);
if (strcmp(ife->name, "lo")==0)
return 0;
if (res >= 0) {
if ((ife->flags & IFF_UP) || *opt_a)
{
ap = get_afntype(ife->addr.sa_family);
strcpy(status.IFdata[i].name, ife->name);
if (ife->has_ip)
{
sprintf(status.IFdata[i].ip, "%s", ap->sprint(&ife->addr, 1));
sprintf(status.IFdata[i].netmask, "%s", ap->sprint(&ife->netmask, 1));
sprintf(status.IFdata[i].gateway, "%s", ap->sprint(&ife->addr, 1));
} else
{
sprintf(status.IFdata[i].ip, "000.000.000.000");
sprintf(status.IFdata[i].netmask, "255.255.255.255");
sprintf(status.IFdata[i].gateway, "000.000.000.000");
}
sprintf(mesg, "menu_add_item SIF %d action {sel. %s} -next CHSET", i, status.IFdata[i].name);
buffer=basic_send(SD, mesg);
}
}
i++;
return res;
}
void autointerfaces(int SD)
{
int res;
int opt_a=0;
/* Create a channel to the NET kernel. */
if ((skfd = sockets_open(0)) < 0) {
perror("socket");
exit(1);
}
res=for_all_interfaces(SD, do_if_action, &opt_a);
close(skfd);
}
void set_main_info(int SD, char *ifname, char *ip, char *netmask, char *gateway)
{
char *buffer;
char mesg[255];
sprintf(mesg, "widget_set main mainscroller 1 1 16 2 v 10 {%*s%*s%*s%*s%*s%*s%*s%*s}",
16, " Watching IF: ",
16, ifname,
16, " IP-Address: ",
16, ip,
16, " Netmask: ",
16, netmask,
16, " Gateway: ",
16, gateway);
buffer=basic_send(SD, mesg);
}
void CHSET_menus_add(int SD)
{
char *buffer;
char mesg[255];
sprintf(mesg, "menu_add_item CHSET CHIP ip {%s IP} -v6 false -value {%s}",
status.IFdata[status.sIF].name, status.IFdata[status.sIF].ip);
buffer=basic_send(SD, mesg);
sprintf(mesg, "menu_add_item CHSET CHNM ip {%s netmask} -v6 false -value {%s}",
status.IFdata[status.sIF].name, status.IFdata[status.sIF].netmask);
buffer=basic_send(SD, mesg);
sprintf(mesg, "menu_add_item CHSET CHGW ip {%s gateway} -v6 false -value {%s}",
status.IFdata[status.sIF].name, status.IFdata[status.sIF].gateway);
buffer=basic_send(SD, mesg);
buffer=basic_send(SD, "menu_set_item CHSET CHIP -next CHNM");
buffer=basic_send(SD, "menu_set_item CHSET CHNM -next CHGW");
set_main_info(SD, status.IFdata[status.sIF].name, status.IFdata[status.sIF].ip, status.IFdata[status.sIF].netmask, status.IFdata[status.sIF].gateway);
}
void CHSET_menus(int SD)
{
char *buffer;
char mesg[255];
sprintf(mesg, "menu_set_item CHSET CHIP -text {%s IP} -v6 false -value {%s}",
status.IFdata[status.sIF].name, status.IFdata[status.sIF].ip);
buffer=basic_send(SD, mesg);
sprintf(mesg, "menu_set_item CHSET CHNM -text {%s netmask} -v6 false -value {%s}",
status.IFdata[status.sIF].name, status.IFdata[status.sIF].netmask);
buffer=basic_send(SD, mesg);
sprintf(mesg, "menu_set_item CHSET CHGW -text {%s gateway} -v6 false -value {%s}",
status.IFdata[status.sIF].name, status.IFdata[status.sIF].gateway);
buffer=basic_send(SD, mesg);
set_main_info(SD, status.IFdata[status.sIF].name, status.IFdata[status.sIF].ip, status.IFdata[status.sIF].netmask, status.IFdata[status.sIF].gateway);
}
void action(int SD, char *input)
{
char *next=input;
char *retstr;
int len=0;
int mode=0;
int myid;
if(DEBUG)
printf("Eingabe: %s\n", input);
while (1)
{
retstr=strtok(next, " \n");
next=NULL;
if (retstr==NULL)
{
input[0]=0; /* wofür war das? */
break;
}
len+=strlen(retstr)+1;
/* key detected? */
switch (mode)
{
case BLANK:
{
if (strcmp(retstr, "update")==0) mode=UPDATE;
if (strcmp(retstr, "leave")==0) mode=MENULEFT;
if (strcmp(retstr, "select")==0) mode=SELECT;
break;
}
case UPDATE:
{
/* if (strcmp(retstr, "sIF")==0) mode=IFSELECTED; */
if (strcmp(retstr, "CHIP")==0) mode=IPCHANGED;
if (strcmp(retstr, "CHNM")==0) mode=NMCHANGED;
if (strcmp(retstr, "CHGW")==0) mode=GWCHANGED;
break;
}
case IFSELECTED:
{
status.sIF=atoi(retstr);
CHSET_menus(SD);
mode=BLANK;
break;
}
case IPCHANGED:
{
strcpy(status.IFdata[status.sIF].ip, retstr);
mode=BLANK;
break;
}
case NMCHANGED:
{
strcpy(status.IFdata[status.sIF].netmask, retstr);
mode=BLANK;
break;
}
case GWCHANGED:
{
strcpy(status.IFdata[status.sIF].gateway, retstr);
mode=BLANK;
break;
}
case MENULEFT:
{
CHSET_menus(SD);
mode=BLANK;
break;
}
case SELECT:
/* Now it gets a bit difficult: If we want to call the
external script, we have to do the fork twice of
wait for the child process (which we don't want to).
The approach ist repeated for every call to external
programm. */
{
if (strcmp(retstr, "APPLY")==0)
{
char mesg[17];
myid=fork();
switch (myid)
{
int mynewid;
case 0:
mynewid=fork();
switch (mynewid)
{
case 0: /* Child of the child */
close(SD);
execl(INTERFACE_SCRIPT,
INTERFACE_SCRIPT,
status.IFdata[status.sIF].name,
status.IFdata[status.sIF].ip,
status.IFdata[status.sIF].netmask,
status.IFdata[status.sIF].gateway,
NULL);
break;
case -1:
sprintf(mesg, "Error %d", errno);
alert_screen(SD, mesg, "during apply.", SUCC_DUR);
exit(0);
break;
default: /* At this point, the child exits and the grandchild's parent is set to "1". */
exit(0);
break;
}
break;
case -1:
sprintf(mesg, "Error %d", errno);
alert_screen(SD, mesg, "during apply.", SUCC_DUR);
break;
default:
sprintf(mesg, "for IF %s", status.IFdata[status.sIF].name);
alert_screen(SD, "Settings applied", mesg, 160);
waitpid(myid, NULL, 0); /* the child's exitstate is read, but we don't need it. */
break;
}
} else if (strcmp(retstr, "HALT")==0)
{
char mesg[17];
myid=fork();
switch (myid)
{
int mynewid;
case 0:
mynewid=fork();
switch(mynewid)
{
case 0:
close(SD);
execl(HALT_SCRIPT,
HALT_SCRIPT,
NULL);
break;
case -1:
sprintf(mesg, "Error %d", errno);
alert_screen(SD, mesg, "during halt.", SUCC_DUR);
exit(0);
break;
default:
exit(0);
break;
}
break;
case -1:
sprintf(mesg, "Error %d", errno);
alert_screen(SD, mesg, "during halt.", SUCC_DUR);
break;
default:
alert_screen(SD, "Going down for", "halt now.", 160);
waitpid(myid, NULL, 0);
break;
}
} else if (strcmp(retstr, "REBOOT")==0)
{
char mesg[17];
myid=fork();
switch (myid)
{
int mynewid;
case 0:
mynewid=fork();
switch (mynewid)
{
case 0:
close(SD);
execl(REBOOT_SCRIPT,
REBOOT_SCRIPT,
NULL);
break;
case -1:
sprintf(mesg, "Error %d", errno);
alert_screen(SD, mesg, "during reboot.", SUCC_DUR);
exit(0);
break;
default:
exit(0);
break;
}
break;
case -1:
sprintf(mesg, "Error %d", errno);
alert_screen(SD, mesg, "during reboot.", SUCC_DUR);
break;
default:
alert_screen(SD, "Going down for", "reboot now.", 160);
waitpid(myid, NULL, 0);
break;
}
} else /* Assume the Selection is a number and refers to the Index of an interface */
{
status.sIF=atoi(retstr);
CHSET_menus(SD);
}
mode=BLANK;
break;
}
}
}
return;
}
int main(int argc, char *argv[])
{
int SD;
int conn_port=13666;
int i;
int j;
char *buffer;
int starttime;
int nowtime;
int devpos=-1;
int manualif=0;
for(i = 1, j = 0; i < argc; i++)
{
if(argv[i][0] == '-')
{
switch(argv[i][1])
{
/* Port number specified */
case 'p':
{
if(argc < i + 1)
print_help();
conn_port = atoi(argv[++i]);
if(conn_port < 1 && conn_port > 0xffff)
fprintf(stderr, "Warning: Port %d outside of standard range\n", conn_port);
break;
}
/* List of devices */
case 'd':
{
devpos=i+1;
manualif=1;
break;
}
/* otherwise... Get help!*/
default:
{
print_help();
exit(0);
break;
}
}
}
}
if (manualif && devpos<1)
{
printf("No interfaces specified, exiting (use -h for usage information).\n");
close(SD);
exit(1);
}
SD=get_connection("localhost", conn_port);
if (SD<0)
exit(0);
init_screen(SD);
buffer=basic_send(SD, "menu_add_item {} SIF menu {Current IF}");
buffer=basic_send(SD, "menu_add_item {} CHSET menu {IF setting}");
if (manualif)
interfaces(SD, argv[devpos]);
else
autointerfaces(SD);
/* buffer=basic_send(SD, "menu_set_item {} SIF -next CHSET"); */ /* Doesn't work like that */
buffer=basic_send(SD, "menu_set_main {}");
/* buffer=basic_send(SD, "widget_add main maintitle title");
buffer=basic_send(SD, "widget_set main maintitle {IF-Status}"); */
buffer=basic_send(SD, "widget_add main mainscroller scroller");
buffer=basic_send(SD, "widget_set main mainscroller 1 1 16 2 v 4 {Please stand by. }");
CHSET_menus_add(SD); /* Remember to set the status.sIF to a valid value before call to CHSET_menus*() (e.g. done by interfaces()). */
buffer=basic_send(SD, "menu_add_item CHSET APPLY action {Apply settings} -next _quit_");
buffer=basic_send(SD, "menu_set_item CHSET CHGW -next APPLY");
buffer=basic_send(SD, "menu_add_item {} ASKREBOOT menu {Confirm reboot?} -is_hidden true");
buffer=basic_send(SD, "menu_add_item ASKREBOOT REBOOT action { [Yes][No]} -next _quit_");
buffer=basic_send(SD, "menu_add_item {} ASKHALT menu {Really halt?} -is_hidden true");
buffer=basic_send(SD, "menu_add_item ASKHALT HALT action { [Yes][No]} -next _quit_");
buffer=basic_send(SD, "menu_add_item {} SHUTDOWN menu {Shutdown}");
buffer=basic_send(SD, "menu_add_item SHUTDOWN DOHALT action {Halt system} -next ASKHALT");
buffer=basic_send(SD, "menu_add_item SHUTDOWN DOREBOOT action {Reboot system} -next ASKREBOOT");
starttime=time(NULL);
while (1)
{
nowtime=time(NULL);
/* sprintf(cmd, "widget_set main c0 1 2 \"%ld\"\n", nowtime-starttime); */
/* if nothing else to do, send noop, so we know for sure, that basic_send gets something to read */
/* buffer=basic_send(SD, "noop\n"); */
buffer=basic_read(SD);
action(SD, buffer);
usleep(250000);
} /* while ((nowtime-starttime)<500); */
close(SD);
return 0;
}
+451
View File
@@ -0,0 +1,451 @@
/*
* lib/inet.c This file contains an implementation of the "INET"
* support functions for the net-tools.
* (NET-3 base distribution).
*
* Version: $Id$
*
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
* Copyright 1993 MicroWalt Corporation
*
* Modified:
*960113 {1.21} Bernd Eckenfels : rresolve cache bug.
*960128 {1.22} Bernd Eckenfels : endian bug in print
*960203 {1.23} Bernd Eckenfels : net-features support
*960217 {1.24} Bernd Eckenfels : get_sname
*960219 {1.25} Bernd Eckenfels : extern int h_errno
*960329 {1.26} Bernd Eckenfels : resolve 255.255.255.255
*980101 {1.27} Bernd Eckenfels : resolve raw sockets in /etc/protocols
*990302 {1.28} Phil Blundell : add netmask to INET_rresolve
*991007 Kurt Garloff : rresolve, resolve: may be hosts
* <garloff@suse.de> store type (host?) in cache
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at
* your option) any later version.
*/
#include "config.h"
/* FIXME. Split this file into inet4.c for the IPv4 specific parts
and inet.c for those shared between IPv4 and IPv6. */
#if HAVE_AFINET || HAVE_AFINET6
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <ctype.h>
#include <errno.h>
#include <netdb.h>
#include <resolv.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include "version.h"
#include "net-support.h"
#include "pathnames.h"
#include "intl.h"
#include "util.h"
extern int h_errno; /* some netdb.h versions don't export this */
/* cache */
struct addr {
struct sockaddr_in addr;
char *name;
int host;
struct addr *next;
};
struct service {
int number;
char *name;
struct service *next;
};
static struct service *tcp_name = NULL, *udp_name = NULL, *raw_name = NULL;
#if HAVE_AFINET
static struct addr *INET_nn = NULL; /* addr-to-name cache */
static int INET_resolve(char *name, struct sockaddr_in *sin, int hostfirst)
{
struct hostent *hp;
struct netent *np;
/* Grmpf. -FvK */
sin->sin_family = AF_INET;
sin->sin_port = 0;
/* Default is special, meaning 0.0.0.0. */
if (!strcmp(name, "default")) {
sin->sin_addr.s_addr = INADDR_ANY;
return (1);
}
/* Look to see if it's a dotted quad. */
if (inet_aton(name, &sin->sin_addr)) {
return 0;
}
/* If we expect this to be a hostname, try hostname database first */
#ifdef DEBUG
if (hostfirst) fprintf (stderr, "gethostbyname (%s)\n", name);
#endif
if (hostfirst &&
(hp = gethostbyname(name)) != (struct hostent *) NULL) {
memcpy((char *) &sin->sin_addr, (char *) hp->h_addr_list[0],
sizeof(struct in_addr));
return 0;
}
/* Try the NETWORKS database to see if this is a known network. */
#ifdef DEBUG
fprintf (stderr, "getnetbyname (%s)\n", name);
#endif
if ((np = getnetbyname(name)) != (struct netent *) NULL) {
sin->sin_addr.s_addr = htonl(np->n_net);
return 1;
}
if (hostfirst) {
/* Don't try again */
errno = h_errno;
return -1;
}
#ifdef DEBUG
res_init();
_res.options |= RES_DEBUG;
#endif
#ifdef DEBUG
fprintf (stderr, "gethostbyname (%s)\n", name);
#endif
if ((hp = gethostbyname(name)) == (struct hostent *) NULL) {
errno = h_errno;
return -1;
}
memcpy((char *) &sin->sin_addr, (char *) hp->h_addr_list[0],
sizeof(struct in_addr));
return 0;
}
/* numeric: & 0x8000: default instead of *,
* & 0x4000: host instead of net,
* & 0x0fff: don't resolve
*/
static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin,
int numeric, unsigned int netmask)
{
struct hostent *ent;
struct netent *np;
struct addr *pn;
u_int32_t ad, host_ad;
int host = 0;
/* Grmpf. -FvK */
if (sin->sin_family != AF_INET) {
#ifdef DEBUG
fprintf(stderr, _("rresolve: unsupport address family %d !\n"), sin->sin_family);
#endif
errno = EAFNOSUPPORT;
return (-1);
}
ad = sin->sin_addr.s_addr;
#ifdef DEBUG
fprintf (stderr, "rresolve: %08lx, mask %08x, num %08x \n", ad, netmask, numeric);
#endif
if (ad == INADDR_ANY) {
if ((numeric & 0x0FFF) == 0) {
if (numeric & 0x8000)
safe_strncpy(name, "default", len);
else
safe_strncpy(name, "*", len);
return (0);
}
}
if (numeric & 0x0FFF) {
safe_strncpy(name, inet_ntoa(sin->sin_addr), len);
return (0);
}
if ((ad & (~netmask)) != 0 || (numeric & 0x4000))
host = 1;
#if 0
INET_nn = NULL;
#endif
pn = INET_nn;
while (pn != NULL) {
if (pn->addr.sin_addr.s_addr == ad && pn->host == host) {
safe_strncpy(name, pn->name, len);
#ifdef DEBUG
fprintf (stderr, "rresolve: found %s %08lx in cache\n", (host? "host": "net"), ad);
#endif
return (0);
}
pn = pn->next;
}
host_ad = ntohl(ad);
np = NULL;
ent = NULL;
if (host) {
#ifdef DEBUG
fprintf (stderr, "gethostbyaddr (%08lx)\n", ad);
#endif
ent = gethostbyaddr((char *) &ad, 4, AF_INET);
if (ent != NULL)
safe_strncpy(name, ent->h_name, len);
} else {
#ifdef DEBUG
fprintf (stderr, "getnetbyaddr (%08lx)\n", host_ad);
#endif
np = getnetbyaddr(host_ad, AF_INET);
if (np != NULL)
safe_strncpy(name, np->n_name, len);
}
if ((ent == NULL) && (np == NULL))
safe_strncpy(name, inet_ntoa(sin->sin_addr), len);
pn = (struct addr *) malloc(sizeof(struct addr));
pn->addr = *sin;
pn->next = INET_nn;
pn->host = host;
pn->name = (char *) malloc(strlen(name) + 1);
strcpy(pn->name, name);
INET_nn = pn;
return (0);
}
static void INET_reserror(char *text)
{
herror(text);
}
/* Display an Internet socket address. */
static char *INET_print(unsigned char *ptr)
{
return (inet_ntoa((*(struct in_addr *) ptr)));
}
/* Display an Internet socket address. */
static char *INET_sprint(struct sockaddr *sap, int numeric)
{
static char buff[128];
if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff));
if (INET_rresolve(buff, sizeof(buff), (struct sockaddr_in *) sap,
numeric, 0xffffff00) != 0)
return (NULL);
return (buff);
}
char *INET_sprintmask(struct sockaddr *sap, int numeric,
unsigned int netmask)
{
static char buff[128];
if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff));
if (INET_rresolve(buff, sizeof(buff), (struct sockaddr_in *) sap,
numeric, netmask) != 0)
return (NULL);
return (buff);
}
static int INET_getsock(char *bufp, struct sockaddr *sap)
{
char *sp = bufp, *bp;
unsigned int i;
unsigned val;
struct sockaddr_in *sin;
sin = (struct sockaddr_in *) sap;
sin->sin_family = AF_INET;
sin->sin_port = 0;
val = 0;
bp = (char *) &val;
for (i = 0; i < sizeof(sin->sin_addr.s_addr); i++) {
*sp = toupper(*sp);
if ((*sp >= 'A') && (*sp <= 'F'))
bp[i] |= (int) (*sp - 'A') + 10;
else if ((*sp >= '0') && (*sp <= '9'))
bp[i] |= (int) (*sp - '0');
else
return (-1);
bp[i] <<= 4;
sp++;
*sp = toupper(*sp);
if ((*sp >= 'A') && (*sp <= 'F'))
bp[i] |= (int) (*sp - 'A') + 10;
else if ((*sp >= '0') && (*sp <= '9'))
bp[i] |= (int) (*sp - '0');
else
return (-1);
sp++;
}
sin->sin_addr.s_addr = htonl(val);
return (sp - bufp);
}
static int INET_input(int type, char *bufp, struct sockaddr *sap)
{
switch (type) {
case 1:
return (INET_getsock(bufp, sap));
case 256:
return (INET_resolve(bufp, (struct sockaddr_in *) sap, 1));
default:
return (INET_resolve(bufp, (struct sockaddr_in *) sap, 0));
}
}
static int INET_getnetmask(char *adr, struct sockaddr *m, char *name)
{
struct sockaddr_in *mask = (struct sockaddr_in *) m;
char *slash, *end;
int prefix;
if ((slash = strchr(adr, '/')) == NULL)
return 0;
*slash++ = '\0';
prefix = strtoul(slash, &end, 0);
if (*end != '\0')
return -1;
if (name) {
sprintf(name, "/%d", prefix);
}
mask->sin_family = AF_INET;
mask->sin_addr.s_addr = htonl(~(0xffffffffU >> prefix));
return 1;
}
struct aftype inet_aftype =
{
"inet", NULL, /*"DARPA Internet", */ AF_INET, sizeof(unsigned long),
INET_print, INET_sprint, INET_input, INET_reserror,
NULL /*INET_rprint */ , NULL /*INET_rinput */ ,
INET_getnetmask,
-1,
NULL
};
#endif /* HAVE_AFINET */
static void add2list(struct service **namebase, struct service *item)
{
if (*namebase == NULL) {
*namebase = item;
item->next = NULL;
} else {
item->next = *namebase;
*namebase = item;
}
}
static struct service *searchlist(struct service *servicebase, int number)
{
struct service *item;
for (item = servicebase; item != NULL; item = item->next) {
if (item->number == number)
return (item);
}
return (NULL);
}
static int read_services(void)
{
struct servent *se;
struct protoent *pe;
struct service *item;
setservent(1);
while ((se = getservent())) {
/* Allocate a service entry. */
item = (struct service *) malloc(sizeof(struct service));
if (item == NULL)
perror("netstat");
item->name = strdup(se->s_name);
item->number = se->s_port;
/* Fill it in. */
if (!strcmp(se->s_proto, "tcp")) {
add2list(&tcp_name, item);
} else if (!strcmp(se->s_proto, "udp")) {
add2list(&udp_name, item);
} else if (!strcmp(se->s_proto, "raw")) {
add2list(&raw_name, item);
}
}
endservent();
setprotoent(1);
while ((pe = getprotoent())) {
/* Allocate a service entry. */
item = (struct service *) malloc(sizeof(struct service));
if (item == NULL)
perror("netstat");
item->name = strdup(pe->p_name);
item->number = htons(pe->p_proto);
add2list(&raw_name, item);
}
endprotoent();
return (0);
}
char *get_sname(int socknumber, char *proto, int numeric)
{
static char buffer[64], init = 0;
struct service *item;
if (socknumber == 0)
return ("*");
if (numeric) {
sprintf(buffer, "%d", ntohs(socknumber));
return (buffer);
}
if (!init) {
(void) read_services();
init = 1;
}
buffer[0] = '\0';
if (!strcmp(proto, "tcp")) {
if ((item = searchlist(tcp_name, socknumber)) != NULL)
sprintf(buffer, "%s", item->name);
} else if (!strcmp(proto, "udp")) {
if ((item = searchlist(udp_name, socknumber)) != NULL)
sprintf(buffer, "%s", item->name);
} else if (!strcmp(proto, "raw")) {
if ((item = searchlist(raw_name, socknumber)) != NULL)
sprintf(buffer, "%s", item->name);
}
if (!buffer[0])
sprintf(buffer, "%d", ntohs(socknumber));
return (buffer);
}
#endif /* HAVE_AFINET || HAVE_AFINET6 */
+936
View File
@@ -0,0 +1,936 @@
/* Code to manipulate interface information, shared between ifconfig and
netstat.
10/1998 partly rewriten by Andi Kleen to support an interface list.
I don't claim that the list operations are efficient @).
8/2000 Andi Kleen make the list operations a bit more efficient.
People are crazy enough to use thousands of aliases now.
$Id$
*/
#include "config.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#if HAVE_AFIPX
#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
#include <netipx/ipx.h>
#else
#include "ipx.h"
#endif
#endif
#if HAVE_AFECONET
#include <neteconet/ec.h>
#endif
#ifdef HAVE_HWSLIP
#include <linux/if_slip.h>
#include <net/if_arp.h>
#endif
#include "net-support.h"
#include "pathnames.h"
#include "version.h"
#include "proc.h"
#include "interface.h"
#include "sockets.h"
#include "util.h"
#include "intl.h"
#ifdef IFF_PORTSEL
const char *if_port_text[][4] =
{
/* Keep in step with <linux/netdevice.h> */
{"unknown", NULL, NULL, NULL},
{"10base2", "bnc", "coax", NULL},
{"10baseT", "utp", "tpe", NULL},
{"AUI", "thick", "db15", NULL},
{"100baseT", NULL, NULL, NULL},
{"100baseTX", NULL, NULL, NULL},
{"100baseFX", NULL, NULL, NULL},
{NULL, NULL, NULL, NULL},
};
#endif
#define IPV6_ADDR_ANY 0x0000U
#define IPV6_ADDR_UNICAST 0x0001U
#define IPV6_ADDR_MULTICAST 0x0002U
#define IPV6_ADDR_ANYCAST 0x0004U
#define IPV6_ADDR_LOOPBACK 0x0010U
#define IPV6_ADDR_LINKLOCAL 0x0020U
#define IPV6_ADDR_SITELOCAL 0x0040U
#define IPV6_ADDR_COMPATv4 0x0080U
#define IPV6_ADDR_SCOPE_MASK 0x00f0U
#define IPV6_ADDR_MAPPED 0x1000U
#define IPV6_ADDR_RESERVED 0x2000U /* reserved address space */
int procnetdev_vsn = 1;
int ife_short;
int if_list_all = 0; /* do we have requested the complete proc list, yet? */
static struct interface *int_list, *int_last;
static int if_readlist_proc(char *);
static struct interface *if_cache_add(char *name)
{
struct interface *ife, **nextp, *new;
if (!int_list)
int_last = NULL;
/* the cache is sorted, so if we hit a smaller if, exit */
for (ife = int_last; ife; ife = ife->prev) {
int n = nstrcmp(ife->name, name);
if (n == 0)
return ife;
if (n < 0)
break;
}
new(new);
safe_strncpy(new->name, name, IFNAMSIZ);
nextp = ife ? &ife->next : &int_list; // keep sorting
new->prev = ife;
new->next = *nextp;
if (new->next)
new->next->prev = new;
else
int_last = new;
*nextp = new;
return new;
}
struct interface *lookup_interface(char *name)
{
/* if we have read all, use it */
if (if_list_all)
return if_cache_add(name);
/* otherwise we read a limited list */
if (if_readlist_proc(name) < 0)
return NULL;
return if_cache_add(name);
}
int for_all_interfaces(int SD, int (*doit) (int, struct interface *, void *), void *cookie)
{
struct interface *ife;
if (!if_list_all && (if_readlist() < 0))
return -1;
for (ife = int_list; ife; ife = ife->next) {
int err = doit(SD, ife, cookie);
if (err)
return err;
}
return 0;
}
int if_cache_free(void)
{
struct interface *ife;
while ((ife = int_list) != NULL) {
int_list = ife->next;
free(ife);
}
int_last = NULL;
if_list_all = 0;
return 0;
}
static int if_readconf(void)
{
int numreqs = 30;
struct ifconf ifc;
struct ifreq *ifr;
int n, err = -1;
int skfd;
/* SIOCGIFCONF currently seems to only work properly on AF_INET sockets
(as of 2.1.128) */
skfd = get_socket_for_af(AF_INET);
if (skfd < 0) {
fprintf(stderr, _("warning: no inet socket available: %s\n"),
strerror(errno));
/* Try to soldier on with whatever socket we can get hold of. */
skfd = sockets_open(0);
if (skfd < 0)
return -1;
}
ifc.ifc_buf = NULL;
for (;;) {
ifc.ifc_len = sizeof(struct ifreq) * numreqs;
ifc.ifc_buf = xrealloc(ifc.ifc_buf, ifc.ifc_len);
if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) {
perror("SIOCGIFCONF");
goto out;
}
if (ifc.ifc_len == sizeof(struct ifreq) * numreqs) {
/* assume it overflowed and try again */
numreqs *= 2;
continue;
}
break;
}
ifr = ifc.ifc_req;
for (n = 0; n < ifc.ifc_len; n += sizeof(struct ifreq)) {
if_cache_add(ifr->ifr_name);
ifr++;
}
err = 0;
out:
free(ifc.ifc_buf);
return err;
}
char *get_name(char *name, char *p)
{
while (isspace(*p))
p++;
while (*p) {
if (isspace(*p))
break;
if (*p == ':') { /* could be an alias */
char *dot = p++;
while (*p && isdigit(*p)) p++;
if (*p == ':') {
/* Yes it is, backup and copy it. */
p = dot;
*name++ = *p++;
while (*p && isdigit(*p)) {
*name++ = *p++;
}
} else {
/* No, it isn't */
p = dot;
}
p++;
break;
}
*name++ = *p++;
}
*name++ = '\0';
return p;
}
int procnetdev_version(char *buf)
{
if (strstr(buf, "compressed"))
return 3;
if (strstr(buf, "bytes"))
return 2;
return 1;
}
int get_dev_fields(char *bp, struct interface *ife)
{
switch (procnetdev_vsn) {
case 3:
sscanf(bp,
"%Lu %Lu %lu %lu %lu %lu %lu %lu %Lu %Lu %lu %lu %lu %lu %lu %lu",
&ife->stats.rx_bytes,
&ife->stats.rx_packets,
&ife->stats.rx_errors,
&ife->stats.rx_dropped,
&ife->stats.rx_fifo_errors,
&ife->stats.rx_frame_errors,
&ife->stats.rx_compressed,
&ife->stats.rx_multicast,
&ife->stats.tx_bytes,
&ife->stats.tx_packets,
&ife->stats.tx_errors,
&ife->stats.tx_dropped,
&ife->stats.tx_fifo_errors,
&ife->stats.collisions,
&ife->stats.tx_carrier_errors,
&ife->stats.tx_compressed);
break;
case 2:
sscanf(bp, "%Lu %Lu %lu %lu %lu %lu %Lu %Lu %lu %lu %lu %lu %lu",
&ife->stats.rx_bytes,
&ife->stats.rx_packets,
&ife->stats.rx_errors,
&ife->stats.rx_dropped,
&ife->stats.rx_fifo_errors,
&ife->stats.rx_frame_errors,
&ife->stats.tx_bytes,
&ife->stats.tx_packets,
&ife->stats.tx_errors,
&ife->stats.tx_dropped,
&ife->stats.tx_fifo_errors,
&ife->stats.collisions,
&ife->stats.tx_carrier_errors);
ife->stats.rx_multicast = 0;
break;
case 1:
sscanf(bp, "%Lu %lu %lu %lu %lu %Lu %lu %lu %lu %lu %lu",
&ife->stats.rx_packets,
&ife->stats.rx_errors,
&ife->stats.rx_dropped,
&ife->stats.rx_fifo_errors,
&ife->stats.rx_frame_errors,
&ife->stats.tx_packets,
&ife->stats.tx_errors,
&ife->stats.tx_dropped,
&ife->stats.tx_fifo_errors,
&ife->stats.collisions,
&ife->stats.tx_carrier_errors);
ife->stats.rx_bytes = 0;
ife->stats.tx_bytes = 0;
ife->stats.rx_multicast = 0;
break;
}
return 0;
}
static int if_readlist_proc(char *target)
{
FILE *fh;
char buf[512];
struct interface *ife;
int err;
fh = fopen(_PATH_PROCNET_DEV, "r");
if (!fh) {
fprintf(stderr, _("Warning: cannot open %s (%s). Limited output.\n"),
_PATH_PROCNET_DEV, strerror(errno));
return -2;
}
fgets(buf, sizeof buf, fh); /* eat line */
fgets(buf, sizeof buf, fh);
#if 0 /* pretty, but can't cope with missing fields */
fmt = proc_gen_fmt(_PATH_PROCNET_DEV, 1, fh,
"face", "", /* parsed separately */
"bytes", "%lu",
"packets", "%lu",
"errs", "%lu",
"drop", "%lu",
"fifo", "%lu",
"frame", "%lu",
"compressed", "%lu",
"multicast", "%lu",
"bytes", "%lu",
"packets", "%lu",
"errs", "%lu",
"drop", "%lu",
"fifo", "%lu",
"colls", "%lu",
"carrier", "%lu",
"compressed", "%lu",
NULL);
if (!fmt)
return -1;
#else
procnetdev_vsn = procnetdev_version(buf);
#endif
err = 0;
while (fgets(buf, sizeof buf, fh)) {
char *s, name[IFNAMSIZ];
s = get_name(name, buf);
ife = if_cache_add(name);
get_dev_fields(s, ife);
ife->statistics_valid = 1;
if (target && !strcmp(target,name))
break;
}
if (ferror(fh)) {
perror(_PATH_PROCNET_DEV);
err = -1;
}
#if 0
free(fmt);
#endif
fclose(fh);
return err;
}
int if_readlist(void)
{
/* caller will/should check not to call this too often
* (i.e. only if if_list_all == 0
*/
int err = 0;
err |= if_readlist_proc(NULL);
err |= if_readconf();
if_list_all = 1;
return err;
}
/* Support for fetching an IPX address */
#if HAVE_AFIPX
static int ipx_getaddr(int sock, int ft, struct ifreq *ifr)
{
((struct sockaddr_ipx *) &ifr->ifr_addr)->sipx_type = ft;
return ioctl(sock, SIOCGIFADDR, ifr);
}
#endif
/* Fetch the interface configuration from the kernel. */
int if_fetch(struct interface *ife)
{
struct ifreq ifr;
int fd;
char *ifname = ife->name;
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0)
return (-1);
ife->flags = ifr.ifr_flags;
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFHWADDR, &ifr) < 0)
memset(ife->hwaddr, 0, 32);
else
memcpy(ife->hwaddr, ifr.ifr_hwaddr.sa_data, 8);
ife->type = ifr.ifr_hwaddr.sa_family;
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFMETRIC, &ifr) < 0)
ife->metric = 0;
else
ife->metric = ifr.ifr_metric;
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFMTU, &ifr) < 0)
ife->mtu = 0;
else
ife->mtu = ifr.ifr_mtu;
#ifdef HAVE_HWSLIP
if (ife->type == ARPHRD_SLIP || ife->type == ARPHRD_CSLIP ||
ife->type == ARPHRD_SLIP6 || ife->type == ARPHRD_CSLIP6 ||
ife->type == ARPHRD_ADAPT) {
#ifdef SIOCGOUTFILL
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGOUTFILL, &ifr) < 0)
ife->outfill = 0;
else
ife->outfill = (unsigned int) ifr.ifr_data;
#endif
#ifdef SIOCGKEEPALIVE
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGKEEPALIVE, &ifr) < 0)
ife->keepalive = 0;
else
ife->keepalive = (unsigned int) ifr.ifr_data;
#endif
}
#endif
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0)
memset(&ife->map, 0, sizeof(struct ifmap));
else
memcpy(&ife->map, &ifr.ifr_map, sizeof(struct ifmap));
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0)
memset(&ife->map, 0, sizeof(struct ifmap));
else
ife->map = ifr.ifr_map;
#ifdef HAVE_TXQUEUELEN
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFTXQLEN, &ifr) < 0)
ife->tx_queue_len = -1; /* unknown value */
else
ife->tx_queue_len = ifr.ifr_qlen;
#else
ife->tx_queue_len = -1; /* unknown value */
#endif
#if HAVE_AFINET
/* IPv4 address? */
fd = get_socket_for_af(AF_INET);
if (fd >= 0) {
strcpy(ifr.ifr_name, ifname);
ifr.ifr_addr.sa_family = AF_INET;
if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
ife->has_ip = 1;
ife->addr = ifr.ifr_addr;
strcpy(ifr.ifr_name, ifname);
if (ioctl(fd, SIOCGIFDSTADDR, &ifr) < 0)
memset(&ife->dstaddr, 0, sizeof(struct sockaddr));
else
ife->dstaddr = ifr.ifr_dstaddr;
strcpy(ifr.ifr_name, ifname);
if (ioctl(fd, SIOCGIFBRDADDR, &ifr) < 0)
memset(&ife->broadaddr, 0, sizeof(struct sockaddr));
else
ife->broadaddr = ifr.ifr_broadaddr;
strcpy(ifr.ifr_name, ifname);
if (ioctl(fd, SIOCGIFNETMASK, &ifr) < 0)
memset(&ife->netmask, 0, sizeof(struct sockaddr));
else
ife->netmask = ifr.ifr_netmask;
} else
memset(&ife->addr, 0, sizeof(struct sockaddr));
}
#endif
#if HAVE_AFATALK
/* DDP address maybe ? */
fd = get_socket_for_af(AF_APPLETALK);
if (fd >= 0) {
strcpy(ifr.ifr_name, ifname);
if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
ife->ddpaddr = ifr.ifr_addr;
ife->has_ddp = 1;
}
}
#endif
#if HAVE_AFIPX
/* Look for IPX addresses with all framing types */
fd = get_socket_for_af(AF_IPX);
if (fd >= 0) {
strcpy(ifr.ifr_name, ifname);
if (!ipx_getaddr(fd, IPX_FRAME_ETHERII, &ifr)) {
ife->has_ipx_bb = 1;
ife->ipxaddr_bb = ifr.ifr_addr;
}
strcpy(ifr.ifr_name, ifname);
if (!ipx_getaddr(fd, IPX_FRAME_SNAP, &ifr)) {
ife->has_ipx_sn = 1;
ife->ipxaddr_sn = ifr.ifr_addr;
}
strcpy(ifr.ifr_name, ifname);
if (!ipx_getaddr(fd, IPX_FRAME_8023, &ifr)) {
ife->has_ipx_e3 = 1;
ife->ipxaddr_e3 = ifr.ifr_addr;
}
strcpy(ifr.ifr_name, ifname);
if (!ipx_getaddr(fd, IPX_FRAME_8022, &ifr)) {
ife->has_ipx_e2 = 1;
ife->ipxaddr_e2 = ifr.ifr_addr;
}
}
#endif
#if HAVE_AFECONET
/* Econet address maybe? */
fd = get_socket_for_af(AF_ECONET);
if (fd >= 0) {
strcpy(ifr.ifr_name, ifname);
if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
ife->ecaddr = ifr.ifr_addr;
ife->has_econet = 1;
}
}
#endif
return 0;
}
int do_if_fetch(struct interface *ife)
{
if (if_fetch(ife) < 0) {
char *errmsg;
if (errno == ENODEV) {
/* Give better error message for this case. */
errmsg = _("Device not found");
} else {
errmsg = strerror(errno);
}
fprintf(stderr, _("%s: error fetching interface information: %s\n"),
ife->name, errmsg);
return -1;
}
return 0;
}
int do_if_print(struct interface *ife, void *cookie)
{
int *opt_a = (int *) cookie;
int res;
res = do_if_fetch(ife);
if (res >= 0) {
if ((ife->flags & IFF_UP) || *opt_a)
ife_print(ife);
}
return res;
}
void ife_print_short(struct interface *ptr)
{
printf("%-5.5s ", ptr->name);
printf("%5d %-2d ", ptr->mtu, ptr->metric);
/* If needed, display the interface statistics. */
if (ptr->statistics_valid) {
printf("%8llu %6lu %6lu %6lu ",
ptr->stats.rx_packets, ptr->stats.rx_errors,
ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors);
printf("%8llu %6lu %6lu %6lu ",
ptr->stats.tx_packets, ptr->stats.tx_errors,
ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors);
} else {
printf("%-56s", _(" - no statistics available -"));
}
/* DONT FORGET TO ADD THE FLAGS IN ife_print_long, too */
if (ptr->flags == 0)
printf(_("[NO FLAGS]"));
if (ptr->flags & IFF_ALLMULTI)
printf("A");
if (ptr->flags & IFF_BROADCAST)
printf("B");
if (ptr->flags & IFF_DEBUG)
printf("D");
if (ptr->flags & IFF_LOOPBACK)
printf("L");
if (ptr->flags & IFF_MULTICAST)
printf("M");
#ifdef HAVE_DYNAMIC
if (ptr->flags & IFF_DYNAMIC)
printf("d");
#endif
if (ptr->flags & IFF_PROMISC)
printf("P");
if (ptr->flags & IFF_NOTRAILERS)
printf("N");
if (ptr->flags & IFF_NOARP)
printf("O");
if (ptr->flags & IFF_POINTOPOINT)
printf("P");
if (ptr->flags & IFF_SLAVE)
printf("s");
if (ptr->flags & IFF_MASTER)
printf("m");
if (ptr->flags & IFF_RUNNING)
printf("R");
if (ptr->flags & IFF_UP)
printf("U");
/* DONT FORGET TO ADD THE FLAGS IN ife_print_long, too */
printf("\n");
}
void ife_print_long(struct interface *ptr)
{
struct aftype *ap;
struct hwtype *hw;
int hf;
int can_compress = 0;
unsigned long long rx, tx, short_rx, short_tx;
const char *Rext = "b";
const char *Text = "b";
#if HAVE_AFIPX
static struct aftype *ipxtype = NULL;
#endif
#if HAVE_AFECONET
static struct aftype *ectype = NULL;
#endif
#if HAVE_AFATALK
static struct aftype *ddptype = NULL;
#endif
#if HAVE_AFINET6
FILE *f;
char addr6[40], devname[20];
struct sockaddr_in6 sap;
int plen, scope, dad_status, if_idx;
extern struct aftype inet6_aftype;
char addr6p[8][5];
#endif
ap = get_afntype(ptr->addr.sa_family);
if (ap == NULL)
ap = get_afntype(0);
hf = ptr->type;
if (hf == ARPHRD_CSLIP || hf == ARPHRD_CSLIP6)
can_compress = 1;
hw = get_hwntype(hf);
if (hw == NULL)
hw = get_hwntype(-1);
printf(_("%-9.9s Link encap:%s "), ptr->name, hw->title);
/* For some hardware types (eg Ash, ATM) we don't print the
hardware address if it's null. */
if (hw->print != NULL && (! (hw_null_address(hw, ptr->hwaddr) &&
hw->suppress_null_addr)))
printf(_("HWaddr %s "), hw->print(ptr->hwaddr));
#ifdef IFF_PORTSEL
if (ptr->flags & IFF_PORTSEL) {
printf(_("Media:%s"), if_port_text[ptr->map.port][0]);
if (ptr->flags & IFF_AUTOMEDIA)
printf(_("(auto)"));
}
#endif
printf("\n");
#if HAVE_AFINET
if (ptr->has_ip) {
printf(_(" %s addr:%s "), ap->name,
ap->sprint(&ptr->addr, 1));
if (ptr->flags & IFF_POINTOPOINT) {
printf(_(" P-t-P:%s "), ap->sprint(&ptr->dstaddr, 1));
}
if (ptr->flags & IFF_BROADCAST) {
printf(_(" Bcast:%s "), ap->sprint(&ptr->broadaddr, 1));
}
printf(_(" Mask:%s\n"), ap->sprint(&ptr->netmask, 1));
}
#endif
#if HAVE_AFINET6
/* FIXME: should be integrated into interface.c. */
if ((f = fopen(_PATH_PROCNET_IFINET6, "r")) != NULL) {
while (fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n",
addr6p[0], addr6p[1], addr6p[2], addr6p[3],
addr6p[4], addr6p[5], addr6p[6], addr6p[7],
&if_idx, &plen, &scope, &dad_status, devname) != EOF) {
if (!strcmp(devname, ptr->name)) {
sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s",
addr6p[0], addr6p[1], addr6p[2], addr6p[3],
addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
inet6_aftype.input(1, addr6, (struct sockaddr *) &sap);
printf(_(" inet6 addr: %s/%d"),
inet6_aftype.sprint((struct sockaddr *) &sap, 1), plen);
printf(_(" Scope:"));
switch (scope) {
case 0:
printf(_("Global"));
break;
case IPV6_ADDR_LINKLOCAL:
printf(_("Link"));
break;
case IPV6_ADDR_SITELOCAL:
printf(_("Site"));
break;
case IPV6_ADDR_COMPATv4:
printf(_("Compat"));
break;
case IPV6_ADDR_LOOPBACK:
printf(_("Host"));
break;
default:
printf(_("Unknown"));
}
printf("\n");
}
}
fclose(f);
}
#endif
#if HAVE_AFIPX
if (ipxtype == NULL)
ipxtype = get_afntype(AF_IPX);
if (ipxtype != NULL) {
if (ptr->has_ipx_bb)
printf(_(" IPX/Ethernet II addr:%s\n"),
ipxtype->sprint(&ptr->ipxaddr_bb, 1));
if (ptr->has_ipx_sn)
printf(_(" IPX/Ethernet SNAP addr:%s\n"),
ipxtype->sprint(&ptr->ipxaddr_sn, 1));
if (ptr->has_ipx_e2)
printf(_(" IPX/Ethernet 802.2 addr:%s\n"),
ipxtype->sprint(&ptr->ipxaddr_e2, 1));
if (ptr->has_ipx_e3)
printf(_(" IPX/Ethernet 802.3 addr:%s\n"),
ipxtype->sprint(&ptr->ipxaddr_e3, 1));
}
#endif
#if HAVE_AFATALK
if (ddptype == NULL)
ddptype = get_afntype(AF_APPLETALK);
if (ddptype != NULL) {
if (ptr->has_ddp)
printf(_(" EtherTalk Phase 2 addr:%s\n"), ddptype->sprint(&ptr->ddpaddr, 1));
}
#endif
#if HAVE_AFECONET
if (ectype == NULL)
ectype = get_afntype(AF_ECONET);
if (ectype != NULL) {
if (ptr->has_econet)
printf(_(" econet addr:%s\n"), ectype->sprint(&ptr->ecaddr, 1));
}
#endif
printf(" ");
/* DONT FORGET TO ADD THE FLAGS IN ife_print_short, too */
if (ptr->flags == 0)
printf(_("[NO FLAGS] "));
if (ptr->flags & IFF_UP)
printf(_("UP "));
if (ptr->flags & IFF_BROADCAST)
printf(_("BROADCAST "));
if (ptr->flags & IFF_DEBUG)
printf(_("DEBUG "));
if (ptr->flags & IFF_LOOPBACK)
printf(_("LOOPBACK "));
if (ptr->flags & IFF_POINTOPOINT)
printf(_("POINTOPOINT "));
if (ptr->flags & IFF_NOTRAILERS)
printf(_("NOTRAILERS "));
if (ptr->flags & IFF_RUNNING)
printf(_("RUNNING "));
if (ptr->flags & IFF_NOARP)
printf(_("NOARP "));
if (ptr->flags & IFF_PROMISC)
printf(_("PROMISC "));
if (ptr->flags & IFF_ALLMULTI)
printf(_("ALLMULTI "));
if (ptr->flags & IFF_SLAVE)
printf(_("SLAVE "));
if (ptr->flags & IFF_MASTER)
printf(_("MASTER "));
if (ptr->flags & IFF_MULTICAST)
printf(_("MULTICAST "));
#ifdef HAVE_DYNAMIC
if (ptr->flags & IFF_DYNAMIC)
printf(_("DYNAMIC "));
#endif
/* DONT FORGET TO ADD THE FLAGS IN ife_print_short */
printf(_(" MTU:%d Metric:%d"),
ptr->mtu, ptr->metric ? ptr->metric : 1);
#ifdef SIOCSKEEPALIVE
if (ptr->outfill || ptr->keepalive)
printf(_(" Outfill:%d Keepalive:%d"),
ptr->outfill, ptr->keepalive);
#endif
printf("\n");
/* If needed, display the interface statistics. */
if (ptr->statistics_valid) {
/* XXX: statistics are currently only printed for the primary address,
* not for the aliases, although strictly speaking they're shared
* by all addresses.
*/
printf(" ");
printf(_("RX packets:%llu errors:%lu dropped:%lu overruns:%lu frame:%lu\n"),
ptr->stats.rx_packets, ptr->stats.rx_errors,
ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors,
ptr->stats.rx_frame_errors);
if (can_compress)
printf(_(" compressed:%lu\n"), ptr->stats.rx_compressed);
rx = ptr->stats.rx_bytes;
tx = ptr->stats.tx_bytes;
short_rx = rx * 10;
short_tx = tx * 10;
if (rx > 1125899906842624ull) {
short_rx /= 1125899906842624ull;
Rext = "PiB";
} else if (rx > 1099511627776ull) {
short_rx /= 1099511627776ull;
Rext = "TiB";
} else if (rx > 1073741824ull) {
short_rx /= 1073741824ull;
Rext = "GiB";
} else if (rx > 1048576) {
short_rx /= 1048576;
Rext = "MiB";
} else if (rx > 1024) {
short_rx /= 1024;
Rext = "KiB";
}
if (tx > 1125899906842624ull) {
short_tx /= 1125899906842624ull;
Text = "PiB";
} else if (tx > 1099511627776ull) {
short_tx /= 1099511627776ull;
Text = "TiB";
} else if (tx > 1073741824ull) {
short_tx /= 1073741824ull;
Text = "GiB";
} else if (tx > 1048576) {
short_tx /= 1048576;
Text = "MiB";
} else if (tx > 1024) {
short_tx /= 1024;
Text = "KiB";
}
printf(" ");
printf(_("TX packets:%llu errors:%lu dropped:%lu overruns:%lu carrier:%lu\n"),
ptr->stats.tx_packets, ptr->stats.tx_errors,
ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors,
ptr->stats.tx_carrier_errors);
printf(_(" collisions:%lu "), ptr->stats.collisions);
if (can_compress)
printf(_("compressed:%lu "), ptr->stats.tx_compressed);
if (ptr->tx_queue_len != -1)
printf(_("txqueuelen:%d "), ptr->tx_queue_len);
printf("\n ");
printf(_("RX bytes:%llu (%lu.%lu %s) TX bytes:%llu (%lu.%lu %s)\n"),
rx, (unsigned long)(short_rx / 10),
(unsigned long)(short_rx % 10), Rext,
tx, (unsigned long)(short_tx / 10),
(unsigned long)(short_tx % 10), Text);
}
if ((ptr->map.irq || ptr->map.mem_start || ptr->map.dma ||
ptr->map.base_addr >= 0x100)) {
printf(" ");
if (ptr->map.irq)
printf(_("Interrupt:%d "), ptr->map.irq);
if (ptr->map.base_addr >= 0x100) /* Only print devices using it for
I/O maps */
printf(_("Base address:0x%x "), ptr->map.base_addr);
if (ptr->map.mem_start) {
printf(_("Memory:%lx-%lx "), ptr->map.mem_start, ptr->map.mem_end);
}
if (ptr->map.dma)
printf(_("DMA chan:%x "), ptr->map.dma);
printf("\n");
}
printf("\n");
}
void ife_print(struct interface *i)
{
if (ife_short)
ife_print_short(i);
else
ife_print_long(i);
}
+100
View File
@@ -0,0 +1,100 @@
struct user_net_device_stats {
unsigned long long rx_packets; /* total packets received */
unsigned long long tx_packets; /* total packets transmitted */
unsigned long long rx_bytes; /* total bytes received */
unsigned long long tx_bytes; /* total bytes transmitted */
unsigned long rx_errors; /* bad packets received */
unsigned long tx_errors; /* packet transmit problems */
unsigned long rx_dropped; /* no space in linux buffers */
unsigned long tx_dropped; /* no space available in linux */
unsigned long rx_multicast; /* multicast packets received */
unsigned long rx_compressed;
unsigned long tx_compressed;
unsigned long collisions;
/* detailed rx_errors: */
unsigned long rx_length_errors;
unsigned long rx_over_errors; /* receiver ring buff overflow */
unsigned long rx_crc_errors; /* recved pkt with crc error */
unsigned long rx_frame_errors; /* recv'd frame alignment error */
unsigned long rx_fifo_errors; /* recv'r fifo overrun */
unsigned long rx_missed_errors; /* receiver missed packet */
/* detailed tx_errors */
unsigned long tx_aborted_errors;
unsigned long tx_carrier_errors;
unsigned long tx_fifo_errors;
unsigned long tx_heartbeat_errors;
unsigned long tx_window_errors;
};
struct interface {
struct interface *next, *prev;
char name[IFNAMSIZ]; /* interface name */
short type; /* if type */
short flags; /* various flags */
int metric; /* routing metric */
int mtu; /* MTU value */
int tx_queue_len; /* transmit queue length */
struct ifmap map; /* hardware setup */
struct sockaddr addr; /* IP address */
struct sockaddr dstaddr; /* P-P IP address */
struct sockaddr broadaddr; /* IP broadcast address */
struct sockaddr netmask; /* IP network mask */
struct sockaddr ipxaddr_bb; /* IPX network address */
struct sockaddr ipxaddr_sn; /* IPX network address */
struct sockaddr ipxaddr_e3; /* IPX network address */
struct sockaddr ipxaddr_e2; /* IPX network address */
struct sockaddr ddpaddr; /* Appletalk DDP address */
struct sockaddr ecaddr; /* Econet address */
int has_ip;
int has_ipx_bb;
int has_ipx_sn;
int has_ipx_e3;
int has_ipx_e2;
int has_ax25;
int has_ddp;
int has_econet;
char hwaddr[32]; /* HW address */
int statistics_valid;
struct user_net_device_stats stats; /* statistics */
int keepalive; /* keepalive value for SLIP */
int outfill; /* outfill value for SLIP */
};
extern int if_fetch(struct interface *ife);
extern int for_all_interfaces(int, int (*)(int, struct interface *, void *), void *);
extern int if_cache_free(void);
extern struct interface *lookup_interface(char *name);
extern int if_readlist(void);
extern int do_if_fetch(struct interface *ife);
extern int do_if_print(struct interface *ife, void *cookie);
extern int procnetdev_version(char *buf);
extern int get_dev_fields(char *bp, struct interface *ife);
extern char * get_name(char *name, char *p);
extern void ife_print(struct interface *ptr);
extern int ife_short;
extern const char *if_port_text[][4];
/* Defines for poor glibc2.0 users, the feature check is done at runtime */
#if !defined(SIOCSIFTXQLEN)
#define SIOCSIFTXQLEN 0x8943
#define SIOCGIFTXQLEN 0x8942
#endif
#if !defined(ifr_qlen)
/* Actually it is ifru_ivalue, but that is not present in 2.0 kernel headers */
#define ifr_qlen ifr_ifru.ifru_mtu
#endif
#define HAVE_TXQUEUELEN
#define HAVE_DYNAMIC
#ifndef IFF_DYNAMIC
#define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses */
#endif
+12
View File
@@ -0,0 +1,12 @@
/* Dummy header for libintl.h */
#if I18N
#include <locale.h>
#undef __OPTIMIZE__
#include <libintl.h>
#define _(String) gettext((String))
#define N_(String) (String)
#else
#define _(String) (String)
#define N_(String) (String)
#endif
+85
View File
@@ -0,0 +1,85 @@
/* lib-myconnect.c:
used by interfacedemo for pylcd device.
*/
/*
Copyright (C) 2005 Silvan Marco Fin <silvan@kernelconcepts.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
/* TCP connection to given host/port
*/
int get_connection(char *peername, int peerport)
{
struct sockaddr_in peeraddr;
int SocketDescriptor;
struct hostent *HostEntry;
HostEntry=gethostbyname(peername);
if (HostEntry==NULL)
{
switch (h_errno)
{
case HOST_NOT_FOUND:
printf("Host not found.\n");
return -1;
break;
case NO_ADDRESS:
printf("No IP found for valid hostname.\n");
return -1;
break;
case NO_RECOVERY:
printf("Name service error.\n");
return -1;
break;
case TRY_AGAIN:
printf("Temporary error in name resolution.\n");
return -1;
break;
default:
break;
}
}
/* peeraddr must contain information to reach the server */
memset(&peeraddr, 0, sizeof(peeraddr));
peeraddr.sin_family = AF_INET;
peeraddr.sin_port = htons(peerport);
peeraddr.sin_addr = *(struct in_addr *) HostEntry->h_addr;
SocketDescriptor=socket(PF_INET, SOCK_STREAM, 0);
if (SocketDescriptor==-1)
{
printf("Error creating socket\n");
return -1;
}
if (connect(SocketDescriptor, (struct sockaddr *) &peeraddr, sizeof(peeraddr))==-1)
{
perror("Error connecting");
return -1;
}
return SocketDescriptor;
}
+40
View File
@@ -0,0 +1,40 @@
/* lib-myconnect.h
used by interfacedemo for pylcd device.
*/
/*
Copyright (C) 2005 Silvan Marco Fin <silvan@kernelconcepts.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
*/
#ifndef LIB_MYCONNECT
#define LIB_MYCONNECT
/*
lib-myconnect.c:
used by interfacedemo to connect to a TCP socket.
*/
/* TCP connection to given host/port
*/
int get_connection(char *peername, int peerport);
#endif
+133
View File
@@ -0,0 +1,133 @@
/* lib-mylcd.h
used by interfacedemo for pylcd device.
*/
/*
Copyright (C) 2005 Silvan Marco Fin <silvan@kernelconcepts.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
*/
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "lib-mylcd.h"
#define DEBUG 0
/* Request information from LCDd */
int get_integer(int SD, char *request)
{
static char output[MAXREAD];
write(SD, request, strlen(request));
read(SD, output, MAXREAD-1);
return atoi(output);
}
/* Used to parse the reply from the hello-msg.
*/
void parse_hello(char *input)
{
char *next=input;
char *retval;
while (1)
{
retval=strtok(next, " ");
next=NULL;
if (retval==NULL)
break;
if (strcmp(retval, "wid")==0)
screen.width=atoi(strtok(next, " "));
if (strcmp(retval, "hgt")==0)
screen.height=atoi(strtok(next, " "));
}
}
int parse_reply(char *input)
{
char *next=input;
char *retstr;
int retint=UNKNOWNKEY;
int inputlen=strlen(input);
int len=0;
printf("Eingabe: %s\n", input);
while (1)
{
retstr=strtok(next, " \n");
next=NULL;
if (retstr==NULL)
{
input[0]=0; /* wofür war das? */
break;
}
len+=strlen(retstr)+1;
/* key detected? */
if (strcmp(retstr, "key")==0)
{
retstr=strtok(next, " \n");
len+=strlen(retstr)+1;
if (strcmp(retstr, "Escape")==0)
retint=ESCAPEKEY;
if (strcmp(retstr, "Down")==0)
retint=DOWNKEY;
if (strcmp(retstr, "Right")==0)
retint=RIGHTKEY;
if (strcmp(retstr, "Enter")==0)
retint=ENTERKEY;
input=strncpy(input, &input[len], inputlen-len+1);
return retint;
}
}
return NOKEY;
}
char *basic_send(int SD, char *request)
{
static char answer[MAXREAD];
if (DEBUG)
printf("Sending command: %s\n", request);
memset(answer, 0, MAXREAD);
write(SD, request, strlen(request));
write(SD, "\n", strlen("\n"));
read(SD, answer, MAXREAD);
if (DEBUG)
printf("Answer to command to LCDproc: %s\n", answer);
return answer;
}
char *basic_read(int SD)
{
static char answer[MAXREAD];
memset(answer, 0, MAXREAD);
if (DEBUG)
printf("Going for read!\n");
read(SD, answer, MAXREAD);
if (DEBUG)
printf("Read returned: %s\n", answer);
return answer;
}
+59
View File
@@ -0,0 +1,59 @@
/* lib-mylcd.h
used by interfacedemo for pylcd device.
*/
/*
Copyright (C) 2005 Silvan Marco Fin <silvan@kernelconcepts.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
*/
#ifndef LIB_MYLCD_H
#define LIB_MYLCD_H
#define MAXREAD 1024
/* Keys */
#define UNKNOWNKEY -1
#define NOKEY 0
#define DOWNKEY 1
#define ENTERKEY 2
#define RIGHTKEY 3
#define ESCAPEKEY 4
struct
{
int width;
int height;
} screen;
/* Request information from LCDd
*/
int get_integer(int SD, char *request);
/* Used to parse the reply from the hello-msg.
*/
void parse_hello(char *input);
int parse_reply(char *input);
char *basic_send(int SD, char *request);
char *basic_read(int SD);
#endif
+59
View File
@@ -0,0 +1,59 @@
/*
* lib/loopback.c This file contains the general hardware types.
*
* Version: $Id$
*
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
* Copyright 1993 MicroWalt Corporation
*
* Modifications:
* 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at
* your option) any later version.
*/
#include "config.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if_arp.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include "net-support.h"
#include "pathnames.h"
#include "intl.h"
#include "util.h"
/* Display an UNSPEC address. */
static char *pr_unspec(unsigned char *ptr)
{
static char buff[64];
char *pos;
unsigned int i;
pos = buff;
for (i = 0; i < sizeof(struct sockaddr); i++) {
pos += sprintf(pos, "%02X-", (*ptr++ & 0377));
}
buff[strlen(buff) - 1] = '\0';
return (buff);
}
struct hwtype unspec_hwtype =
{
"unspec", NULL, /*"UNSPEC", */ -1, 0,
pr_unspec, NULL, NULL
};
struct hwtype loop_hwtype =
{
"loop", NULL, /*"Local Loopback", */ ARPHRD_LOOPBACK, 0,
NULL, NULL, NULL
};
+244
View File
@@ -0,0 +1,244 @@
/*
* lib/support.h This file contains the definitions of what is in the
* support library. Most of all, it defines structures
* for accessing support modules, and the function proto-
* types.
*
* NET-LIB A collection of functions used from the base set of the
* NET-3 Networking Distribution for the LINUX operating
* system. (net-tools, net-drivers)
*
* Version: lib/net-support.h 1.35 (1996-01-01)
*
* Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de>
*
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
* Copyright 1993 MicroWalt Corporation
*
* Modifications:
*960125 {1.20} Bernd Eckenfels: reformated, layout
*960202 {1.30} Bernd Eckenfels: rprint in aftype
*960206 {1.31} Bernd Eckenfels: route_init
*960219 {1.32} Bernd Eckenfels: type for ap->input()
*960322 {1.33} Bernd Eckenfels: activate_ld and const in get_hwtype
*960413 {1.34} Bernd Eckenfels: new RTACTION suport
*990101 {1.35} Bernd Eckenfels: print_(hw|af)list support, added kerneldefines
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at
* your option) any later version.
*/
#include <sys/socket.h>
/* This structure defines protocol families and their handlers. */
struct aftype {
char *name;
char *title;
int af;
int alen;
char *(*print) (unsigned char *);
char *(*sprint) (struct sockaddr *, int numeric);
int (*input) (int type, char *bufp, struct sockaddr *);
void (*herror) (char *text);
int (*rprint) (int options);
int (*rinput) (int typ, int ext, char **argv);
/* may modify src */
int (*getmask) (char *src, struct sockaddr * mask, char *name);
int fd;
char *flag_file;
};
extern struct aftype *aftypes[];
/* This structure defines hardware protocols and their handlers. */
struct hwtype {
char *name;
char *title;
int type;
int alen;
char *(*print) (unsigned char *);
int (*input) (char *, struct sockaddr *);
int (*activate) (int fd);
int suppress_null_addr;
};
extern struct hwtype *get_hwtype(const char *name);
extern struct hwtype *get_hwntype(int type);
extern void print_hwlist(int type);
extern struct aftype *get_aftype(const char *name);
extern struct aftype *get_afntype(int type);
extern void print_aflist(int type);
extern int hw_null_address(struct hwtype *hw, void *addr);
extern int getargs(char *string, char *arguments[]);
extern int get_socket_for_af(int af);
extern void getroute_init(void);
extern void setroute_init(void);
extern void activate_init(void);
extern int route_info(const char *afname, int flags);
extern int route_edit(int action, const char *afname, int flags, char **argv);
extern int activate_ld(const char *hwname, int fd);
#define RTACTION_ADD 1
#define RTACTION_DEL 2
#define RTACTION_HELP 3
#define RTACTION_FLUSH 4
#define RTACTION_SHOW 5
#define FLAG_EXT 3 /* AND-Mask */
#define FLAG_NUM_HOST 4
#define FLAG_NUM_PORT 8
#define FLAG_NUM_USER 16
#define FLAG_NUM (FLAG_NUM_HOST|FLAG_NUM_PORT|FLAG_NUM_USER)
#define FLAG_SYM 32
#define FLAG_CACHE 64
#define FLAG_FIB 128
#define FLAG_VERBOSE 256
extern int ip_masq_info(int numeric_host, int numeric_port, int ext);
extern int INET_rprint(int options);
extern int INET6_rprint(int options);
extern int DDP_rprint(int options);
extern int IPX_rprint(int options);
extern int NETROM_rprint(int options);
extern int AX25_rprint(int options);
extern int X25_rprint(int options);
extern int INET_rinput(int action, int flags, char **argv);
extern int INET6_rinput(int action, int flags, char **argv);
extern int DDP_rinput(int action, int flags, char **argv);
extern int IPX_rinput(int action, int flags, char **argv);
extern int NETROM_rinput(int action, int flags, char **argv);
extern int AX25_rinput(int action, int flags, char **argv);
extern int X25_rinput(int action, int flags, char **argv);
extern int aftrans_opt(const char *arg);
extern void aftrans_def(char *tool, char *argv0, char *dflt);
extern char *get_sname(int socknumber, char *proto, int numeric);
extern int flag_unx;
extern int flag_ipx;
extern int flag_ax25;
extern int flag_ddp;
extern int flag_netrom;
extern int flag_x25;
extern int flag_inet;
extern int flag_inet6;
extern char afname[];
#define AFTRANS_OPTS \
{"ax25", 0, 0, 1}, \
{"x25", 0, 0, 1}, \
{"ip", 0, 0, 1}, \
{"ipx", 0, 0, 1}, \
{"appletalk", 0, 0, 1}, \
{"netrom", 0, 0, 1}, \
{"inet", 0, 0, 1}, \
{"inet6", 0, 0, 1}, \
{"ddp", 0, 0, 1}, \
{"unix", 0, 0, 1}, \
{"tcpip", 0, 0, 1}
#define AFTRANS_CNT 11
#define EINTERN(file, text) fprintf(stderr, \
_("%s: Internal Error `%s'.\n"),file,text);
#define ENOSUPP(A,B) fprintf(stderr,\
_("%s: feature `%s' not supported.\n" \
"Please recompile `net-tools' with "\
"newer kernel source or full configuration.\n"),A,B)
#define ESYSNOT(A,B) fprintf(stderr, _("%s: no support for `%s' on this system.\n"),A,B)
#define E_NOTFOUND 8
#define E_SOCK 7
#define E_LOOKUP 6
#define E_VERSION 5
#define E_USAGE 4
#define E_OPTERR 3
#define E_INTERN 2
#define E_NOSUPP 1
/* ========== Kernel Defines =============
* Since it is not a good idea to depend on special kernel sources for the headers
* and since the libc6 Headers are not always up to date, we keep a copy of the
* most often used Flags in this file. We realy need a way to keep them up-to-date.
* Perhaps anybody knows how the glibc2 folk is doing it? -ecki
*/
/* Keep this ins sync with /usr/src/linux/include/linux/rtnetlink.h */
#define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
#define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
#define RTNH_F_ONLINK 4 /* Gateway is forced on link */
/* Keep this in sync with /usr/src/linux/include/linux/in_route.h */
#define RTCF_DEAD RTNH_F_DEAD
#define RTCF_ONLINK RTNH_F_ONLINK
/* #define RTCF_NOPMTUDISC RTM_F_NOPMTUDISC */
#define RTCF_NOTIFY 0x00010000
#define RTCF_DIRECTDST 0x00020000
#define RTCF_REDIRECTED 0x00040000
#define RTCF_TPROXY 0x00080000
#define RTCF_FAST 0x00200000
#define RTCF_MASQ 0x00400000
#define RTCF_SNAT 0x00800000
#define RTCF_DOREDIRECT 0x01000000
#define RTCF_DIRECTSRC 0x04000000
#define RTCF_DNAT 0x08000000
#define RTCF_BROADCAST 0x10000000
#define RTCF_MULTICAST 0x20000000
#define RTCF_REJECT 0x40000000
#define RTCF_LOCAL 0x80000000
/* Keep this in sync with /usr/src/linux/include/linux/ipv6_route.h */
#ifndef RTF_DEFAULT
#define RTF_DEFAULT 0x00010000 /* default - learned via ND */
#endif
#define RTF_ALLONLINK 0x00020000 /* fallback, no routers on link */
#ifndef RTF_ADDRCONF
#define RTF_ADDRCONF 0x00040000 /* addrconf route - RA */
#endif
#define RTF_NONEXTHOP 0x00200000 /* route with no nexthop */
#define RTF_EXPIRES 0x00400000
#define RTF_CACHE 0x01000000 /* cache entry */
#define RTF_FLOW 0x02000000 /* flow significant route */
#define RTF_POLICY 0x04000000 /* policy route */
#define RTF_LOCAL 0x80000000
/* Keep this in sync with /usr/src/linux/include/linux/route.h */
#define RTF_UP 0x0001 /* route usable */
#define RTF_GATEWAY 0x0002 /* destination is a gateway */
#define RTF_HOST 0x0004 /* host entry (net otherwise) */
#define RTF_REINSTATE 0x0008 /* reinstate route after tmout */
#define RTF_DYNAMIC 0x0010 /* created dyn. (by redirect) */
#define RTF_MODIFIED 0x0020 /* modified dyn. (by redirect) */
#define RTF_MTU 0x0040 /* specific MTU for this route */
#ifndef RTF_MSS
#define RTF_MSS RTF_MTU /* Compatibility :-( */
#endif
#define RTF_WINDOW 0x0080 /* per route window clamping */
#define RTF_IRTT 0x0100 /* Initial round trip time */
#define RTF_REJECT 0x0200 /* Reject route */
/* this is a 2.0.36 flag from /usr/src/linux/include/linux/route.h */
#define RTF_NOTCACHED 0x0400 /* this route isn't cached */
#ifdef HAVE_AFECONET
#ifndef AF_ECONET
#define AF_ECONET 19 /* Acorn Econet */
#endif
#endif
/* End of lib/support.h */
+157
View File
@@ -0,0 +1,157 @@
/* Copyright 1998 by Andi Kleen. Subject to the GPL. */
/* rewritten by bernd eckenfels because of complicated alias semantic */
/* $Id$ */
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "util.h"
/* return numerical :999 suffix or null. sideeffect: replace ':' with \0 */
char* cutalias(char* name)
{
int digit = 0;
int pos;
for(pos=strlen(name); pos>0; pos--)
{
if (name[pos-1]==':' && digit)
{
name[pos-1]='\0';
return name+pos;
}
if (!isdigit(name[pos-1]))
break;
digit = 1;
}
return NULL;
}
/* return index of last non digit or -1 if it does not end with digits */
int rindex_nondigit(char *name)
{
int pos = strlen(name);
for(pos=strlen(name); pos>0; pos--)
{
if (!isdigit(name[pos-1]))
return pos;
}
return 0;
}
/* like strcmp(), but knows about numbers and ':' alias suffix */
int nstrcmp(const char *ap, const char *bp)
{
char *a = (char*)strdup(ap);
char *b = (char*)strdup(bp);
char *an, *bn;
int av = 0, bv = 0;
char *aalias=cutalias(a);
char *balias=cutalias(b);
int aindex=rindex_nondigit(a);
int bindex=rindex_nondigit(b);
int complen=(aindex<bindex)?aindex:bindex;
int res = strncmp(a, b, complen);
if (res != 0)
{ free(a); free(b); return res; }
if (aindex > bindex)
{ free(a); free(b); return 1; }
if (aindex < bindex)
{ free(a); free(b); return -1; }
an = a+aindex;
bn = b+bindex;
av = atoi(an);
bv = atoi(bn);
if (av < bv)
{ free(a); free(b); return -1; }
if (av > bv)
{ free(a); free(b); return 1; }
av = -1;
if (aalias != NULL)
av = atoi(aalias);
bv = -1;
if (balias != NULL)
bv = atoi(balias);
free(a); free(b);
if (av < bv)
return -1;
if (av > bv)
return 1;
return 0;
}
#ifdef NSTRCMP_TEST
int cs(int s)
{
if (s < 0) return -1;
if (s > 0) return 1;
return 0;
}
int dotest(char* a, char* b, int exp)
{
int res = nstrcmp(a, b);
int err = (cs(res) != cs(exp));
printf("nstrcmp(\"%s\", \"%s\")=%d %d %s\n", a, b, res, exp, err?"WRONG":"OK");
return err;
}
int main()
{
int err = 0;
err |= dotest("eth1", "eth1", 0);
err |= dotest("eth0:1", "eth0:1", 0);
err |= dotest("lan", "lan", 0);
err |= dotest("100", "100", 0);
err |= dotest("", "", 0);
err |= dotest(":", ":", 0);
err |= dotest("a:b:c", "a:b:c", 0);
err |= dotest("a:", "a:", 0);
err |= dotest(":a", ":a", 0);
err |= dotest("a", "aa", -1);
err |= dotest("eth0", "eth1", -1);
err |= dotest("eth1", "eth20", -1);
err |= dotest("eth20", "eth100", -1);
err |= dotest("eth1", "eth13", -1);
err |= dotest("eth", "eth2", -1);
err |= dotest("eth0:1", "eth0:2", -1);
err |= dotest("eth1:10", "eth13:10", -1);
err |= dotest("eth1:1", "eth1:13", -1);
err |= dotest("a", "a:", -1);
err |= dotest("aa", "a", 1);
err |= dotest("eth2", "eth1", 1);
err |= dotest("eth13", "eth1", 1);
err |= dotest("eth2", "eth", 1);
err |= dotest("eth2:10", "eth2:1", 1);
err |= dotest("eth2:5", "eth2:4", 1);
err |= dotest("eth3:2", "eth2:3", 1);
err |= dotest("eth13:1", "eth1:0", 1);
err |= dotest("a:", "a", 1);
err |= dotest("a1b12", "a1b2", 1);
return err;
}
#endif
+52
View File
@@ -0,0 +1,52 @@
/*
* lib/pathnames.h This file contains the definitions of the path
* names used by the NET-LIB.
*
* NET-LIB
*
* Version: lib/pathnames.h 1.37 (1997-08-23)
*
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
*/
/* pathnames of the procfs files used by NET. */
#define _PATH_PROCNET_IGMP "/proc/net/igmp"
#define _PATH_PROCNET_IGMP6 "/proc/net/igmp6"
#define _PATH_PROCNET_TCP "/proc/net/tcp"
#define _PATH_PROCNET_TCP6 "/proc/net/tcp6"
#define _PATH_PROCNET_UDP "/proc/net/udp"
#define _PATH_PROCNET_UDP6 "/proc/net/udp6"
#define _PATH_PROCNET_RAW "/proc/net/raw"
#define _PATH_PROCNET_RAW6 "/proc/net/raw6"
#define _PATH_PROCNET_UNIX "/proc/net/unix"
#define _PATH_PROCNET_ROUTE "/proc/net/route"
#define _PATH_PROCNET_ROUTE6 "/proc/net/ipv6_route"
#define _PATH_PROCNET_RTCACHE "/proc/net/rt_cache"
#define _PATH_PROCNET_AX25_ROUTE "/proc/net/ax25_route"
#define _PATH_PROCNET_NR "/proc/net/nr"
#define _PATH_PROCNET_NR_NEIGH "/proc/net/nr_neigh"
#define _PATH_PROCNET_NR_NODES "/proc/net/nr_nodes"
#define _PATH_PROCNET_ARP "/proc/net/arp"
#define _PATH_PROCNET_AX25 "/proc/net/ax25"
#define _PATH_PROCNET_IPX "/proc/net/ipx"
#define _PATH_PROCNET_IPX_ROUTE "/proc/net/ipx_route"
#define _PATH_PROCNET_ATALK "/proc/net/appletalk"
#define _PATH_PROCNET_IP_BLK "/proc/net/ip_block"
#define _PATH_PROCNET_IP_FWD "/proc/net/ip_forward"
#define _PATH_PROCNET_IP_ACC "/proc/net/ip_acct"
#define _PATH_PROCNET_IP_MASQ "/proc/net/ip_masquerade"
#define _PATH_PROCNET_NDISC "/proc/net/ndisc"
#define _PATH_PROCNET_IFINET6 "/proc/net/if_inet6"
#define _PATH_PROCNET_DEV "/proc/net/dev"
#define _PATH_PROCNET_RARP "/proc/net/rarp"
#define _PATH_ETHERS "/etc/ethers"
#define _PATH_PROCNET_ROSE_ROUTE "/proc/net/rose_routes"
#define _PATH_PROCNET_X25 "/proc/net/x25"
#define _PATH_PROCNET_X25_ROUTE "/proc/net/x25_routes"
#define _PATH_PROCNET_DEV_MCAST "/proc/net/dev_mcast"
#define _PATH_PROCNET_ATALK_ROUTE "/proc/net/atalk_route"
/* pathname for the netlink device */
#define _PATH_DEV_ROUTE "/dev/route"
/* End of pathnames.h */
+56
View File
@@ -0,0 +1,56 @@
/*
* lib/ppp.c This file contains the SLIP support for the NET-2 base
* distribution.
*
* Version: $Id$
*
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
* Copyright 1993 MicroWalt Corporation
*
* Modified by Alan Cox, May 94 to cover NET-3
*
* Changes:
* 980701 {1.12} Arnaldo Carvalho de Melo - GNU gettext instead of catgets
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at
* your option) any later version.
*/
#include "config.h"
#if HAVE_HWPPP
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if_arp.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include "net-support.h"
#include "pathnames.h"
#include "intl.h"
/* Start the PPP encapsulation on the file descriptor. */
static int do_ppp(int fd)
{
fprintf(stderr, _("You cannot start PPP with this program.\n"));
return -1;
}
struct hwtype ppp_hwtype =
{
"ppp", NULL, /*"Point-Point Protocol", */ ARPHRD_PPP, 0,
NULL, NULL, do_ppp, 0
};
#endif /* HAVE_PPP */
+5
View File
@@ -0,0 +1,5 @@
/* Generate a suitable scanf format for a column title line */
char *proc_gen_fmt(char *name, int more, FILE * fh,...);
int proc_guess_fmt(char *name, FILE* fh,...);
+25
View File
@@ -0,0 +1,25 @@
#!/bin/sh
### MyHalt ###
#
# used by interfacedemo for pylcd device.
#
# Copyright (C) 2005 Silvan Marco Fin <silvan@kernelconcepts.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
#
echo -e "Externel halt-script calld: Halt requested, simulating halt."
+24
View File
@@ -0,0 +1,24 @@
#!/bin/sh
### MyIpSet ###
#
# used by interfacedemo for pylcd device.
#
# Copyright (C) 2005 Silvan Marco Fin <silvan@kernelconcepts.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
#
echo -e "External Skript to configure interface called for: $1 set to\nIP: $2\nNetmask: $3\nGateway: $4"
+25
View File
@@ -0,0 +1,25 @@
#!/bin/sh
### MyReboot ###
#
# used by interfacedemo for pylcd device.
#
# Copyright (C) 2005 Silvan Marco Fin <silvan@kernelconcepts.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
#
echo -e "External reboot script called: Reboot requested, simulating reboot."
+65
View File
@@ -0,0 +1,65 @@
/* sockets.c. Rewriten by Andi Kleen. Subject to the GPL. */
/* philb 14/11/98: we now stash the socket file descriptor inside
the `aftype' structure rather than keeping it in a pile of separate
variables. This is necessary so that "ifconfig eth0 broadcast ..."
issues ioctls to the right socket for the address family in use;
picking one at random doesn't always work. */
#include <sys/socket.h>
#include <stdio.h>
#include <unistd.h>
#include "config.h"
#include "sockets.h"
#include "intl.h"
#include "util.h"
#include "net-support.h"
int skfd = -1; /* generic raw socket desc. */
int sockets_open(int family)
{
struct aftype **aft;
int sfd = -1;
static int force = -1;
if (force < 0) {
force = 0;
if (kernel_version() < KRELEASE(2, 1, 0))
force = 1;
if (access("/proc/net", R_OK))
force = 1;
}
for (aft = aftypes; *aft; aft++) {
struct aftype *af = *aft;
int type = SOCK_DGRAM;
if (af->af == AF_UNSPEC)
continue;
if (family && family != af->af)
continue;
if (af->fd != -1) {
sfd = af->fd;
continue;
}
/* Check some /proc file first to not stress kmod */
if (!family && !force && af->flag_file) {
if (access(af->flag_file, R_OK))
continue;
}
#if HAVE_AFNETROM
if (af->af == AF_NETROM)
type = SOCK_SEQPACKET;
#endif
#if HAVE_AFX25
if (af->af == AF_X25)
type = SOCK_SEQPACKET;
#endif
af->fd = socket(af->af, type, 0);
if (af->fd >= 0)
sfd = af->fd;
}
if (sfd < 0)
fprintf(stderr, _("No usable address families found.\n"));
return sfd;
}
+4
View File
@@ -0,0 +1,4 @@
extern int skfd, ipx_sock, ax25_sock, rose_sock, x25_sock, inet_sock, inet6_sock,
ddp_sock, ec_sock;
extern int sockets_open(int family);
+43
View File
@@ -0,0 +1,43 @@
/*
* Tunnel.c, Alan Cox 1995.
*
*/
#include "config.h"
#if HAVE_HWTUNNEL
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if_arp.h>
#include <linux/if_ether.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include "net-support.h"
#include "pathnames.h"
extern struct hwtype ether_hwtype;
static char *pr_tunnel(unsigned char *ptr)
{
return ("");
}
static int in_tunnel(char *bufp, struct sockaddr *sap)
{
return (-1);
}
struct hwtype tunnel_hwtype =
{
"tunnel", NULL, /*"IPIP Tunnel", */ ARPHRD_TUNNEL, 0,
pr_tunnel, in_tunnel, NULL, 0
};
#endif /* HAVE_HWTUNNEL */
+97
View File
@@ -0,0 +1,97 @@
/*
* lib/unix.c This file contains the general hardware types.
*
* Version: $Id$
*
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
* Copyright 1993 MicroWalt Corporation
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at
* your option) any later version.
*/
#include "config.h"
#include <sys/types.h>
#include <sys/socket.h>
#if HAVE_AFUNIX
#include <sys/un.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include "net-support.h"
#include "pathnames.h"
#include "intl.h"
#include "util.h"
/* Display an UNSPEC address. */
static char *UNSPEC_print(unsigned char *ptr)
{
static char buff[64];
char *pos;
unsigned int i;
pos = buff;
for (i = 0; i < sizeof(struct sockaddr); i++) {
pos += sprintf(pos, "%02X-", (*ptr++ & 0377));
}
buff[strlen(buff) - 1] = '\0';
return (buff);
}
/* Display an UNSPEC socket address. */
static char *UNSPEC_sprint(struct sockaddr *sap, int numeric)
{
static char buf[64];
if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf));
return (UNSPEC_print(sap->sa_data));
}
#if HAVE_AFUNIX
/* Display a UNIX domain address. */
static char *UNIX_print(unsigned char *ptr)
{
return (ptr);
}
/* Display a UNIX domain address. */
static char *UNIX_sprint(struct sockaddr *sap, int numeric)
{
static char buf[64];
if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf));
return (UNIX_print(sap->sa_data));
}
struct aftype unix_aftype =
{
"unix", NULL, /*"UNIX Domain", */ AF_UNIX, 0,
UNIX_print, UNIX_sprint, NULL, NULL,
NULL, NULL, NULL,
-1,
"/proc/net/unix"
};
#endif /* HAVE_AFUNIX */
struct aftype unspec_aftype =
{
"unspec", NULL, /*"UNSPEC", */ AF_UNSPEC, 0,
UNSPEC_print, UNSPEC_sprint, NULL, NULL,
NULL,
};
+51
View File
@@ -0,0 +1,51 @@
/* Copyright 1998 by Andi Kleen. Subject to the GPL. */
/* $Id$ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/utsname.h>
#include "util.h"
static void oom(void)
{
fprintf(stderr, "out of virtual memory\n");
exit(2);
}
void *xmalloc(size_t sz)
{
void *p = calloc(sz, 1);
if (!p)
oom();
return p;
}
void *xrealloc(void *oldp, size_t sz)
{
void *p = realloc(oldp, sz);
if (!p)
oom();
return p;
}
int kernel_version(void)
{
struct utsname uts;
int major, minor, patch;
if (uname(&uts) < 0)
return -1;
if (sscanf(uts.release, "%d.%d.%d", &major, &minor, &patch) != 3)
return -1;
return KRELEASE(major, minor, patch);
}
/* Like strncpy but make sure the resulting string is always 0 terminated. */
char *safe_strncpy(char *dst, const char *src, size_t size)
{
dst[size-1] = '\0';
return strncpy(dst,src,size-1);
}
+19
View File
@@ -0,0 +1,19 @@
#include <stddef.h>
void *xmalloc(size_t sz);
void *xrealloc(void *p, size_t sz);
#define new(p) ((p) = xmalloc(sizeof(*(p))))
int kernel_version(void);
#define KRELEASE(maj,min,patch) ((maj) * 10000 + (min)*1000 + (patch))
int nstrcmp(const char *, const char *);
char *safe_strncpy(char *dst, const char *src, size_t size);
#define netmin(a,b) ((a)<(b) ? (a) : (b))
#define netmax(a,b) ((a)>(b) ? (a) : (b))
+1
View File
@@ -0,0 +1 @@
#define RELEASE "net-tools 1.60"
+52
View File
@@ -0,0 +1,52 @@
Dear lcdproc community,
I've added support for the LEDs on the Pyramid LC-Display to the
pylcd driver of lcdproc.
Since it seems that LEDs on an LCD are not directly supported by the
lcdproc API I've used the "output" command of the server to trigger the
LEDs, similar to what the IOWarrior driver does.
The Pyramid LC-Display exists in two different versions, with 3 and with
9 LEDs. 2 of these LEDs can not be controlled by software but are
usually hard wired to power and HDD. The other 1 or 7 LEDs can now be
controlled by sending an "output" command to the server. The one
argument to the output command is a bitmask that controls the LEDs.
bit 0: LED3
bit 1: LED4
bit 2: LED5
bit 3: LED6
bit 4: LED7
bit 5: LED8
bit 6: LED9
There's no way of finding out whether 3 or 9 LEDs are available, so it
is up to the software to do the right thing.
Example:
telnet localhost 13666
hello
output 67
will light up LEDs 3, 4 and 9.
output 0
will clear all LEDs.
More information on the Pyramid LC-Display can be found here:
http://www.pyramid.de/e/produkte/server/pyramid-lcd.php
Please apply attached patch to the lcdproc CVS.
Any comments are welcome.
Regards,
Stefan Reinauer
--
coresystems GmbH · Brahmsstr. 16 · D-79104 Freiburg i. Br.
Tel.: +49 761 7668825 · Fax: +49 761 7664613
Email: info@coresystems.de · http://www.coresystems.de/