📄 ip_setup.cxx
字号:
wireless_check->value(1); wireless_check->do_callback(); essid_tmp[0] = '\0'; pix_comm_wireless_get_essid(DEV_ETH0, essid_tmp); strcpy(vals[ESSID], "\""); strcat(vals[ESSID], essid_tmp); strcat(vals[ESSID], "\""); pix_comm_wireless_get_encode(DEV_ETH0, vals[WEPID]); if (vals[ESSID][0] != 0) { essid_input->value(essid_tmp); if (vals[WEPID][0] != 0) { wep_check->value(1); wep_check->do_callback(); wep_input->value(vals[WEPID]); } } } else { wireless_check->value(0); essid_input->value(""); wep_check->value(0); wep_input->value(""); wireless_check->do_callback(); wep_check->do_callback(); } set_button_label(); set_status_box(TYPE_ETH); set_status_box(TYPE_WVLAN); // Set str values for ip, netmask, and broadcast sprintf(vals[IPADDR], "%d.%d.%d.%d", (unsigned char) (ip_info.addr >> 24) & 0xFF, (unsigned char) (ip_info.addr >> 16) & 0xFF, (unsigned char) (ip_info.addr >> 8) & 0xFF, (unsigned char) ip_info.addr & 0xFF); sprintf(vals[NETMASK], "%d.%d.%d.%d", (unsigned char) (ip_info.netmask >> 24) & 0xFF, (unsigned char) (ip_info.netmask >> 16) & 0xFF, (unsigned char) (ip_info.netmask >> 8) & 0xFF, (unsigned char) ip_info.netmask & 0xFF); sprintf(vals[BROADCAST], "%d.%d.%d.%d", (unsigned char) (ip_info.broadcast >> 24) & 0xFF, (unsigned char) (ip_info.broadcast >> 16) & 0xFF, (unsigned char) (ip_info.broadcast >> 8) & 0xFF, (unsigned char) ip_info.broadcast & 0xFF); ip_address_->set_ip_inputs(vals[IPADDR], true); netmask_->set_ip_inputs(vals[NETMASK], true); broadcast_->set_ip_inputs(vals[BROADCAST], true); // Set gateway char buf[255]; if (PIX_COMM_ACTIVE == eth0_active_ || PIX_COMM_ACTIVE == wvlan_active_) { unsigned long gway; pix_comm_get_default_gateway(&gway); sprintf(vals[GATEWAY], "%d.%d.%d.%d", (unsigned char) (gway >> 24) & 0xFF, (unsigned char) (gway >> 16) & 0xFF, (unsigned char) (gway >> 8) & 0xFF, (unsigned char) gway & 0xFF); } else { FILE *fp = fopen(GATEWAY_FILE, "r"); if (NULL != fp) { if (NULL != fgets(buf, sizeof(buf) - 1, fp)) { fclose(fp); strncpy(vals[GATEWAY], buf, sizeof(vals[GATEWAY])); } } } gateway_->set_ip_inputs(vals[GATEWAY], true); pix_sys_get_net_value(DHCP, &dhcp); if ('Y' == dhcp || 'y' == dhcp) { dhcp_button_->value(1); strcpy(vals[PROTO], "dynamic"); } else { dhcp_button_->value(0); strcpy(vals[PROTO], "static"); } dhcp_button_->do_callback(); if (have_wireless_lan_) pix_comm_set_netscript_values(netconf, (const char **) keys, (const char **) vals, MAX_KEYS); else pix_comm_set_netscript_values(netconf, (const char **) keys, (const char **) vals, MAX_KEYS - 2); // don't include ESSID/WEPID keys NetConfig::I()->write_net_values(); set_button_label(); for (int i = 0; i < MAX_KEYS; i++) { delete[]keys[i]; delete[]vals[i]; keys[i] = NULL; vals[i] = NULL; }}/////////////////////////////////////////////////////////////// Function: IP_Setup::set_status_box// Description: This function sets the text in the status_box_ // Parametets: char *status - string containing status // Returns: none ////////////////////////////////////////////////////////////voidIP_Setup::set_status_box(int type, char *status){ if (TYPE_ETH == type) { eth0_status_box_->value(status); eth0_status_box_->redraw(); } if (TYPE_WVLAN == type) { wvlan_status_box_->value(status); wvlan_status_box_->redraw(); }}/////////////////////////////////////////////////////////////// Function: IP_Setup::set_status_box// Description: This function sets the text in the status_box_ // Parametets: none // Returns: none ////////////////////////////////////////////////////////////voidIP_Setup::set_status_box(int type){ char *status; if (TYPE_ETH == type) { if (PIX_COMM_ACTIVE == eth0_active_) { status = " Interface eth0 is active"; } else { status = " Interface eth0 is not active"; } eth0_status_box_->value(status); eth0_status_box_->redraw(); } if (TYPE_WVLAN == type) { if (PIX_COMM_ACTIVE == wvlan_active_) { status = " Interface wvlan0 is active"; } else { status = " Interface wvlan0 is not active"; } wvlan_status_box_->value(status); wvlan_status_box_->redraw(); }}/////////////////////////////////////////////////////////////// Method net_down()// Description: This function brings the ethernet down// Parametets: none// Returns: int err ////////////////////////////////////////////////////////////intIP_Setup::net_down(){ pid_t childpid; int child_status; int idx; int err = 0; // bool have_dev_wvlan0 = get_have_wvlan0_value(); bool dhcp_state = get_dhcp_value(); //bool have_dev_eth0 = get_have_dev_eth0_value(); if ((childpid = fork()) == -1) { perror("net_down (FORK)"); return (PIX_COMM_ERROR); } else if (childpid == 0) { for (idx = 3; idx < 20; idx++) close(idx); err = execl("/bin/sh", "sh", ifdown, netconf, NULL); exit(0); } // in parent else { waitpid(childpid, &child_status, 0); if (0 == child_status) { set_eth0_active_status(PIX_COMM_INACTIVE); set_dhcp_value(dhcp_state); } else { perror("net_down (EXECL)"); set_status_box(TYPE_ETH, " Error shutting down interface eth0"); } return child_status; }}////////////////////////////////////////////////////////////// Function: net_up// Description: this function brings the ethernet up// Parameters: none// Return: int err////////////////////////////////////////////////////////////intIP_Setup::net_up(){ int err = 0; bool dhcp_state = get_dhcp_value(); //bool have_dev_wvlan0 = get_have_wvlan0_value(); //bool have_dev_eth0 = get_have_dev_eth0_value(); pid_t childpid; int child_status; int idx; if ((childpid = fork()) == -1) { perror("net_down (FORK)"); return (PIX_COMM_ERROR); } else if (childpid == 0) { for (idx = 3; idx < 20; idx++) close(idx); err = execl("/bin/sh", "sh", ifup, netconf, NULL); exit(0); } // in parent else { waitpid(childpid, &child_status, 0); if (0 == child_status) { set_eth0_active_status(PIX_COMM_ACTIVE); set_dhcp_value(dhcp_state); } else if (err < 0) { perror("net_up (EXECL)"); set_status_box(TYPE_ETH, " Error starting interface eth0"); } return child_status; }}/////////////////////////////////////////////////////////////// Function: IP_Setup::IP_Setup// Description: This function is the constructor for the IP_Setup// object. It determines the look of the UI. // Parametets: Fl_Tabs *tabs - pointer to the tabs that this// object belongs to// Fl_Window *win - pointer to the parent window// of the object// Returns: none ////////////////////////////////////////////////////////////#include <iostream.h>IP_Setup::IP_Setup(){ _inst = this; ifup = new char[255]; ifdown = new char[255]; netconf = new char[255]; getGblParStr("scripts", "ifup", ifup, 255); getGblParStr("scripts", "ifdown", ifdown, 255); getGblParStr("scripts", "netconf", netconf, 255); cout << "ifup = " << ifup << endl; cout << "ifdown = " << ifdown << endl; cout << "netconf = " << netconf << endl; wireless_name = new char[255]; ip_setup_win_ = new NxPimWindow("TCP/IP Setup", ipMenuItems, MENU); NxApp::Instance()->add_window((Fl_Window *) ip_setup_win_-> GetWindowPtr()); ip_setup_group_ = new Fl_Group(W_X, W_Y, W_W, W_H); int oset = 12; // DHCP dhcp_button_ = new NxCheckButton(BUTTON_X, MB_Y + (2 * oset), "DHCP"); dhcp_button_->callback(dhcp_button_cb, this); // IP int i_oset = 65; ip_address_ = new IP_Input(BUTTON_X + i_oset, MB_Y + (4 * oset), 140, 20, "IP Address:"); netmask_ = new IP_Input(BUTTON_X + i_oset, MB_Y + (6 * oset), 140, 20, "Netmask:"); broadcast_ = new IP_Input(BUTTON_X + i_oset, MB_Y + (8 * oset), 140, 20, "Broadcast:"); gateway_ = new IP_Input(BUTTON_X + i_oset, MB_Y + (10 * oset), 140, 20, "Gateway:"); /////////// // Wireless /////////// // Wireless NxCheckButton & callback (If checked, activate ESSID & WEP NxCheckButton & deactivate WEP NxInput) wireless_check = new NxCheckButton(BUTTON_X, MB_Y + (12 * oset), "Wireless"); wireless_check->callback(wireless_check_cb, &inputs); // ESSID //////// // ESSID NxInput box essid_input = new NxInput(BUTTON_X + i_oset - 5, MB_Y + (14 * oset), 130, 20, "ESS ID:"); essid_input->deactivate(); inputs.essid_input = essid_input; // WEP ////// // WEP NxCheckButton & callback (If checked, activate WEP NxInput) wep_check = new NxCheckButton(BUTTON_X + oset + 6, MB_Y + (16 * oset), "WEP"); wep_check->deactivate(); inputs.wep_check = wep_check; wep_check->callback(wep_check_cb, &inputs); // WEP NxInput box wep_input = new NxInput(BUTTON_X + i_oset + 25, MB_Y + (18 * oset), 100, 20, "WEP ID::"); wep_input->deactivate(); inputs.wep_input = wep_input; // Status Box eth0_status_box_ = new NxOutput(0, MB_Y + (17 * oset), W_W, 50, ""); NxApp::Instance()->big_font(eth0_status_box_); eth0_status_box_->hide(); // Status Box (We don't need this any more) wvlan_status_box_ = new NxOutput(30, 175, 180, 20, ""); wvlan_status_box_->hide(); // Buttons set_button_ = new NxButton(BUTTON_X, BUTTON_Y, BUTTON_WIDTH, BUTTON_HEIGHT, "Set"); set_button_->callback(set_button_cb, this); start_stop_button_ = new NxButton(BUTTON_X + (1 * BUTTON_WIDTH) + 3, BUTTON_Y, BUTTON_WIDTH, BUTTON_HEIGHT, "Stop"); start_stop_button_->callback(start_stop_button_cb, this); reset_button_ = new NxButton(BUTTON_X + (2 * BUTTON_WIDTH) + 6, BUTTON_Y, BUTTON_WIDTH, BUTTON_HEIGHT, "Reset"); reset_button_->callback(reset_button_cb, this); ip_setup_group_->end(); ip_setup_win_->add((Fl_Widget *) ip_setup_group_); set_status_box(TYPE_ETH); set_status_box(TYPE_WVLAN); set_have_if_flags(); // Sets have lo, eth0 set_have_wireless_value(); // Sets have wireless //get_ip_info();}/////////////////////////////////////////////////////////////// Function: IP_Setup::~IP_Setup// Description: This function is the deconstructor for the IP_Setup// object. // Parametets: none // Returns: none ////////////////////////////////////////////////////////////IP_Setup::~IP_Setup(){ delete[]ifup; delete[]ifdown; delete[]netconf; delete[]wireless_name; wireless_name = ifup = ifdown = netconf = NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -