📄 ip_setup.cxx
字号:
/* * Copyright (c) 2003 Century Software, Inc. All Rights Reserved. * * This file is part of the PIXIL Operating Environment * * The use, copying and distribution of this file is governed by one * of two licenses, the PIXIL Commercial License, or the GNU General * Public License, version 2. * * Licensees holding a valid PIXIL Commercial License may use this file * in accordance with the PIXIL Commercial License Agreement provided * with the Software. Others are governed under the terms of the GNU * General Public License version 2. * * This file may be distributed and/or modified under the terms of the * GNU General Public License version 2 as published by the Free * Software Foundation and appearing in the file LICENSE.GPL included * in the packaging of this file. * * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE. * * RESTRICTED RIGHTS LEGEND * * Use, duplication, or disclosure by the government is subject to * restriction as set forth in paragraph (b)(3)(b) of the Rights in * Technical Data and Computer Software clause in DAR 7-104.9(a). * * See http://www.pixil.org/gpl/ for GPL licensing * information. * * See http://www.pixil.org/license.html or * email cetsales@centurysoftware.com for information about the PIXIL * Commercial License Agreement, or if any conditions of this licensing * are not clear to you. */#include "ip_setup.h"#include "net_config.h"extern "C"{#include <pixlib/pixlib.h>#include <pixlib/pix_comm_proto.h>#include <unistd.h>#include <stdio.h>#include <string.h>#include <sys/types.h>#include <sys/wait.h>}#include <nxoutput.h>Fl_Menu_Item ipMenuItems[] = { {"TCP/IP Setup", 0, NetConfig::show_ip}, {"DNS Setup", 0, NetConfig::show_dns}, {"Modem Setup", 0, NetConfig::show_modem}, {0}, {0}};IP_Setup * IP_Setup::_inst;char * IP_Setup::netconf;char *IP_Setup::get_ip_value(){ ip_address_->get_ip_inputs(false); return ip_address_->get_ip_inputs(false);}/////////////////////////////////////////////////////////////// Function: IP_Setup::set_wireless_value()// Description: This function set the value of the// wireles button depending if the interface// exists or not// Parametets: none// Returns: none////////////////////////////////////////////////////////////voidIP_Setup::set_have_wireless_value(){ if (PIX_COMM_OK == pix_comm_wireless_get_name(DEV_ETH0, wireless_name)) { if (0 == strcmp(wireless_name, WNAME)) { have_wireless_lan_ = true; } }}/////////////////////////////////////////////////////////////// Function: IP_Setup::get_dhcp_value()// Description: This function returns the value of the// dhcp button// Parametets: none// Returns: bool - true if button is pressed// false if button is not pressed ////////////////////////////////////////////////////////////bool IP_Setup::get_dhcp_value(){ if (0 == dhcp_button_->value()) { return false; } else { return true; }}/////////////////////////////////////////////////////////////// Function: IP_Setup::dhcp_button_cb()// Description: This function is the callback when the // dhcp button is pressed. It causes the input boxes// to either be activated or deactivated depending// on the state of the dhcp button.// Parametets: Fl_Widget *widget - widget doing the calling// void *parent - the widgets parent// Returns: none ////////////////////////////////////////////////////////////voidIP_Setup::dhcp_button_cb(Fl_Widget * widget, void *parent){ IP_Setup *ip_setup = (IP_Setup *) parent; NxCheckButton *button = (NxCheckButton *) widget; if (0 == button->value()) { ip_setup->ip_address_->activate(); ip_setup->netmask_->activate(); ip_setup->broadcast_->activate(); ip_setup->gateway_->activate(); } if (1 == button->value()) { ip_setup->ip_address_->deactivate(); ip_setup->netmask_->deactivate(); ip_setup->broadcast_->deactivate(); ip_setup->gateway_->deactivate(); }}/////////////////////////////////////////////////////////////// Function: IP_Setup::start_stop_button_cb()// Description: This function is the callback when the // the start_stop_button is pressed. It either stops// or starts the network depending on the status// of the network.// Parametets: Fl_Widget *widget - widget doing the calling// void *parent - the widgets parent// Returns: none ////////////////////////////////////////////////////////////voidIP_Setup::start_stop_button_cb(Fl_Widget * widget, void *parent){ IP_Setup *ip_parent = (IP_Setup *) parent; NetConfig::I()->write_net_values(); if (PIX_COMM_ACTIVE == ip_parent->get_eth0_active_status() || PIX_COMM_ACTIVE == ip_parent->get_wvlan_active_status()) { IP_Setup::IP()->net_down(); ip_parent->start_stop_button_->label("Start"); ip_parent->start_stop_button_->redraw(); } else { IP_Setup::IP()->net_up(); ip_parent->start_stop_button_->label("Stop"); ip_parent->start_stop_button_->redraw(); }}/////////////////////////////////////////////////////////////// Function: IP_Setup::set_button_label// Description: This function sets the label on the start_stop_button// determined by if the network is active or not // Parametets: none // Returns: none ////////////////////////////////////////////////////////////voidIP_Setup::set_button_label(){ if (PIX_COMM_ACTIVE == eth0_active_ || PIX_COMM_ACTIVE == wvlan_active_) { start_stop_button_->label("Stop"); } else { start_stop_button_->label("Start"); } start_stop_button_->redraw();}/////////////////////////////////////////////////////////////// Function: IP_Setup::set_button_cb// Description: This function is the call made when the // set button is pressed. It saves the input box// values, stops the network and brings the// network back up// Parametets: Fl_Widget *widget - widget that is doing the call// void *parent - parent object of the widget // Returns: none ////////////////////////////////////////////////////////////voidIP_Setup::set_button_cb(Fl_Widget * widget, void *parent){ IP_Setup *ip_parent = (IP_Setup *) parent; int err = 0; char *keys[MAX_KEYS]; char *vals[MAX_KEYS]; for (int i = 0; i < MAX_KEYS; i++) { keys[i] = new char[MAX_VALS]; vals[i] = new char[MAX_VALS]; keys[i][0] = '\0'; vals[i][0] = '\0'; } strcpy(keys[DEVICE], KEY_DEVICE); strcpy(keys[PROTO], KEY_PROTO); strcpy(keys[IPADDR], KEY_IPADDR); strcpy(keys[NETMASK], KEY_NETMASK); strcpy(keys[BROADCAST], KEY_BROADCAST); strcpy(keys[GATEWAY], KEY_GATEWAY); strcpy(keys[ESSID], KEY_ESSID); strcpy(keys[WEPID], KEY_WEPID); // Set device if (ip_parent->have_dev_eth0_) strcpy(vals[DEVICE], DEV_ETH0); // Get string values for ip, netmask, broadcast, essid, and wepid strcpy(vals[IPADDR], ip_parent->get_ip_value()); strcpy(vals[NETMASK], ip_parent->get_netmask_value()); strcpy(vals[BROADCAST], ip_parent->get_broadcast_value()); strcpy(vals[GATEWAY], ip_parent->get_gateway_value()); if (ip_parent->wireless_check->value()) { char essid_tmp[MAX_VALS]; essid_tmp[0] = '\0'; strcpy(essid_tmp, "\""); strcat(essid_tmp, ip_parent->essid_input->value()); strcat(essid_tmp, "\""); strcpy(vals[ESSID], essid_tmp); if (ip_parent->wep_check->value()) strcpy(vals[WEPID], ip_parent->wep_input->value()); } // Take the network down err = IP_Setup::IP()->net_down(); NetConfig::I()->write_net_values(); if (0 == err) { // Write new netscript values if (ip_parent->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); // no essid and no wepid } err = IP_Setup::IP()->net_up(); ip_parent->get_ip_info(); // Memory management for (int i = 0; i < MAX_KEYS; i++) { delete[]keys[i]; delete[]vals[i]; keys[i] = NULL; vals[i] = NULL; } } ip_parent->set_button_label();}/////////////////////////////////////////////////////////////// Function: IP_Setup::reset_button_cb// Description: This function is the call made when the // reset button is pressed. It changes the values// of the inputs boxes back to the last saved state// Parametets: Fl_Widget *widget - widget that is doing the call// void *parent - parent object of the widget // Returns: none ////////////////////////////////////////////////////////////voidIP_Setup::reset_button_cb(Fl_Widget * widget, void *parent){ IP_Setup *ip_parent = (IP_Setup *) parent; ip_parent->get_ip_info();}/////////////////////////////////////////////////////////////// Function: IP_Setup::set_have_if_flags// Description: This function set the have_dev_eth0 and have_wvlan// flags // Parametets: none// Returns: none ////////////////////////////////////////////////////////////voidIP_Setup::set_have_if_flags(){ int err = 0; int count = MAX_ETH_DEVS; int wcount = MAX_ETH_DEVS; pix_comm_interface_t eth_list[MAX_ETH_DEVS]; pix_comm_interface_t wireless_list[MAX_ETH_DEVS]; err = pix_comm_wireless_get_if_list(wireless_list, &wcount); if (0 <= err) { err = -1; for (int idx = 0; idx <= count; idx++) { if (0 == strcmp(wireless_list[idx].name, WV_LAN)) { have_dev_wvlan_ = true; err = 0; break; } } } err = pix_comm_get_if_list(PIX_COMM_TYPE_ETHERNET, eth_list, &count); if (0 <= err) { err = -1; for (int idx = 0; idx <= count; idx++) { if (0 == strcmp(eth_list[idx].name, DEV_ETH0)) { have_dev_eth0_ = true; err = 0; break; } } }}/////////////////////////////////////////////////////////////// Function: IP_Setup::get_ip_info// Description: This function loads the ipnut boxes of the // user interface, it gets the values from// reading values from current network settings// or from a specified file, and then writes// out the settings by calling write_net_values.// Parametets: none// Returns: none ////////////////////////////////////////////////////////////voidIP_Setup::get_ip_info(){ char dhcp; pix_comm_ipaddr_t ip_info; char essid_tmp[MAX_VALS]; char *keys[MAX_KEYS]; char *vals[MAX_KEYS]; for (int i = 0; i < MAX_KEYS; i++) { keys[i] = new char[MAX_VALS]; vals[i] = new char[MAX_VALS]; keys[i][0] = '\0'; vals[i][0] = '\0'; } strcpy(keys[DEVICE], KEY_DEVICE); strcpy(keys[PROTO], KEY_PROTO); strcpy(keys[IPADDR], KEY_IPADDR); strcpy(keys[NETMASK], KEY_NETMASK); strcpy(keys[BROADCAST], KEY_BROADCAST); strcpy(keys[GATEWAY], KEY_GATEWAY); strcpy(keys[ESSID], KEY_ESSID); strcpy(keys[WEPID], KEY_WEPID); // currently can only get config for one dev // get wvlan first for wirelless because // eth0 can also be wirelless if (true == have_dev_wvlan_) { pix_comm_get_ip_address(WV_LAN, &ip_info); wvlan_active_ = pix_comm_if_active(WV_LAN); } if (true == have_dev_eth0_) { pix_comm_get_ip_address(DEV_ETH0, &ip_info); eth0_active_ = pix_comm_if_active(DEV_ETH0); strcpy(vals[DEVICE], DEV_ETH0); } if (true == have_wireless_lan_) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -