📄 networking.c
字号:
if (configtype == 0) needcards = 1; else if (configtype == 1 || configtype == 2 || configtype == 4) needcards = 2; else if (configtype == 7) needcards = 4; else needcards = 3; /* This is the green card. */ sofarallocated = 1; findkey(kv, "GREEN_DRIVER", currentdriver); findkey(kv, "GREEN_DRIVER_OPTIONS", currentdriveroptions); strcpy(displaydriver, currentdriver); if (countcards() > 1) strcpy(currentdriver, ""); abort = 0; /* Keep going till all cards are got, or they give up. */ while (sofarallocated < needcards && !abort) { countofcards = countcards(); /* This is how many cards were added by the last module. */ toallocate = countofcards - sofarallocated; while (toallocate > 0 && sofarallocated < needcards) { findnicdescription(displaydriver, temp); sprintf(message, ctr[TR_UNCLAIMED_DRIVER], temp); c = 0; choice = 0; strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp); if (HAS_BLUE && !strlen(temp)) { sections[c] = blue; c++; } strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp); if (HAS_ORANGE && !strlen(temp)) { sections[c] = orange; c++; } strcpy(temp, ""); findkey(kv, "RED_DEV", temp); if (HAS_RED && !strlen(temp)) { sections[c] = red; c++; } sections[c] = NULL; rc = newtWinMenu(ctr[TR_CARD_ASSIGNMENT], message, 50, 5, 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 0 || rc == 1) { /* Now we see which iface needs its settings changed. */ sprintf(nexteth, "eth%d", sofarallocated); if (strcmp(sections[choice], blue) == 0) { replacekeyvalue(kv, "BLUE_DEV", nexteth); replacekeyvalue(kv, "BLUE_DRIVER", currentdriver); replacekeyvalue(kv, "BLUE_DRIVER_OPTIONS", currentdriveroptions); replacekeyvalue(kv, "BLUE_DISPLAYDRIVER", displaydriver); sofarallocated++; toallocate--; strcpy(currentdriver, ""); strcpy(currentdriveroptions, ""); } if (strcmp(sections[choice], orange) == 0) { replacekeyvalue(kv, "ORANGE_DEV", nexteth); replacekeyvalue(kv, "ORANGE_DRIVER", currentdriver); replacekeyvalue(kv, "ORANGE_DRIVER_OPTIONS", currentdriveroptions); replacekeyvalue(kv, "ORANGE_DISPLAYDRIVER", displaydriver); sofarallocated++; toallocate--; strcpy(currentdriver, ""); strcpy(currentdriveroptions, ""); } if (strcmp(sections[choice], red) == 0) { replacekeyvalue(kv, "RED_DEV", nexteth); replacekeyvalue(kv, "RED_DRIVER", currentdriver); replacekeyvalue(kv, "RED_DRIVER_OPTIONS", currentdriveroptions); replacekeyvalue(kv, "RED_DISPLAYDRIVER", displaydriver); sofarallocated++; toallocate--; strcpy(currentdriver, ""); strcpy(currentdriveroptions, ""); } } else { break; } } /* Need another module! The nitty gritty code is in libsmooth. */ if (sofarallocated < needcards) { rc = newtWinTernary(ctr[TR_CARD_ASSIGNMENT], ctr[TR_PROBE], ctr[TR_SELECT], ctr[TR_CANCEL], ctr[TR_NO_UNALLOCATED_CARDS]); if (rc == 0 || rc == 1) { probecards(currentdriver, currentdriveroptions); if (!strlen(currentdriver)) errorbox(ctr[TR_PROBE_FAILED]); } else if (rc == 2) choosecards(currentdriver, currentdriveroptions); else abort = 1; strcpy(displaydriver, currentdriver); } } countofcards = countcards(); if (countofcards >= needcards) { newtWinMessage(ctr[TR_CARD_ASSIGNMENT], ctr[TR_OK], ctr[TR_ALL_CARDS_SUCCESSFULLY_ALLOCATED]); } else errorbox(ctr[TR_NOT_ENOUGH_CARDS_WERE_ALLOCATED]); writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); freekeyvalues(kv); netaddresschange = 1; return 1;}/* Let user change GREEN address. */int greenaddressmenu(void){ struct keyvalue *kv = initkeyvalues(); char message[1000]; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } sprintf(message, ctr[TR_WARNING_LONG], NAME); rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message); if (rc == 0 || rc == 1) { if (changeaddress(kv, "GREEN", 0, "")) { netaddresschange = 1; writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); writehostsfiles(); } } freekeyvalues(kv); return 0;}/* They can change BLUE, ORANGE and GREEN too :) */int addressesmenu(void){ struct keyvalue *kv = initkeyvalues(); struct keyvalue *mainkv = initkeyvalues(); int rc = 0; char *sections[5]; char *green = "GREEN"; char *orange = "ORANGE"; char *blue = "BLUE"; char *red = "RED"; int c = 0; char greenaddress[STRING_SIZE]; char oldgreenaddress[STRING_SIZE]; char temp[STRING_SIZE]; char temp2[STRING_SIZE]; char message[1000]; int configtype; int done; int choice; char hostname[STRING_SIZE]; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); freekeyvalues(mainkv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings"))) { freekeyvalues(kv); freekeyvalues(mainkv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); sections[c] = green; c++; if (HAS_BLUE) { sections[c] = blue; c++; } if (HAS_ORANGE) { sections[c] = orange; c++; } if (HAS_RED) { sections[c] = red; c++; } sections[c] = NULL; choice = 0; done = 0; while (!done) { rc = newtWinMenu(ctr[TR_ADDRESS_SETTINGS], ctr[TR_SELECT_THE_INTERFACE_YOU_WISH_TO_RECONFIGURE], 50, 5, 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL); if (rc == 0 || rc == 1) { if (strcmp(sections[choice], "GREEN") == 0) { findkey(kv, "GREEN_ADDRESS", oldgreenaddress); sprintf(message, ctr[TR_WARNING_LONG], NAME); rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message); if (rc == 0 || rc == 1) { if (changeaddress(kv, "GREEN", 0, "")) { netaddresschange = 1; writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); writehostsfiles(); findkey(kv, "GREEN_ADDRESS", greenaddress); snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress); snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress); replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2); chown (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99); } } } if (strcmp(sections[choice], "BLUE") == 0) { if (changeaddress(kv, "BLUE", 0, "")) netaddresschange = 1; } if (strcmp(sections[choice], "ORANGE") == 0) { if (changeaddress(kv, "ORANGE", 0, "")) netaddresschange = 1; } if (strcmp(sections[choice], "RED") == 0) { strcpy(hostname, ""); findkey(mainkv, "HOSTNAME", hostname); if (changeaddress(kv, "RED", 1, hostname)) netaddresschange = 1; } } else done = 1; } writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); freekeyvalues(kv); freekeyvalues(mainkv); return 0;}/* DNS and default gateway.... */int dnsgatewaymenu(void){ struct keyvalue *kv = initkeyvalues(); char message[1000]; char temp[STRING_SIZE] = "0"; struct newtWinEntry entries[DNSGATEWAY_TOTAL+1]; char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */ int error; int configtype; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); if (RED_IS_NOT_ETH) { freekeyvalues(kv); errorbox(ctr[TR_DNS_GATEWAY_WITH_GREEN]); return 0; } entries[DNS1].text = ctr[TR_PRIMARY_DNS]; strcpy(temp, ""); findkey(kv, "DNS1", temp); values[DNS1] = strdup(temp); entries[DNS1].value = &values[DNS1]; entries[DNS1].flags = 0; entries[DNS2].text = ctr[TR_SECONDARY_DNS]; strcpy(temp, ""); findkey(kv, "DNS2", temp); values[DNS2] = strdup(temp); entries[DNS2].value = &values[DNS2]; entries[DNS2].flags = 0; entries[DEFAULT_GATEWAY].text = ctr[TR_DEFAULT_GATEWAY]; strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); values[DEFAULT_GATEWAY] = strdup(temp); entries[DEFAULT_GATEWAY].value = &values[DEFAULT_GATEWAY]; entries[DEFAULT_GATEWAY].flags = 0; entries[DNSGATEWAY_TOTAL].text = NULL; entries[DNSGATEWAY_TOTAL].value = NULL; entries[DNSGATEWAY_TOTAL].flags = 0; do { error = 0; rc = newtWinEntries(ctr[TR_DNS_AND_GATEWAY_SETTINGS], ctr[TR_DNS_AND_GATEWAY_SETTINGS_LONG], 50, 5, 5, 18, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 0 || rc == 1) { strcpy(message, ctr[TR_INVALID_FIELDS]); if (strlen(values[DNS1])) { if (inet_addr(values[DNS1]) == INADDR_NONE) { strcat(message, ctr[TR_PRIMARY_DNS_CR]); error = 1; } } if (strlen(values[DNS2])) { if (inet_addr(values[DNS2]) == INADDR_NONE) { strcat(message, ctr[TR_SECONDARY_DNS_CR]); error = 1; } } if (strlen(values[DEFAULT_GATEWAY])) { if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE) { strcat(message, ctr[TR_DEFAULT_GATEWAY_CR]); error = 1; } } if (!strlen(values[DNS1]) && strlen(values[DNS2])) { strcpy(message, ctr[TR_SECONDARY_WITHOUT_PRIMARY_DNS]); error = 1; } if (error) errorbox(message); else { replacekeyvalue(kv, "DNS1", values[DNS1]); replacekeyvalue(kv, "DNS2", values[DNS2]); replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]); netaddresschange = 1; free(values[DNS1]); free(values[DNS2]); free(values[DEFAULT_GATEWAY]); writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); } } } while (error); freekeyvalues(kv); return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -