⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 piipcfg.c

📁 VIA VT6524 8口网管交换机源码
💻 C
字号:
/*
 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
 * All rights reserved.
 *
 * This software is copyrighted by and is the sole property of
 * VIA Networking Technologies, Inc. This software may only be used
 * in accordance with the corresponding license agreement. Any unauthorized
 * use, duplication, transmission, distribution, or disclosure of this
 * software is expressly forbidden.
 *
 * This software is provided by VIA Networking Technologies, Inc. "as is"
 * and any express or implied warranties, including, but not limited to, the
 * implied warranties of merchantability and fitness for a particular purpose
 * are disclaimed. In no event shall VIA Networking Technologies, Inc.
 * be liable for any direct, indirect, incidental, special, exemplary, or
 * consequential damages.
 *
 *
 * File:
 *
 * Purpose:
 *
 * Author:  Tevin Chen
 *
 * Date:    Jan 08, 2002
 *
 * Functions:
 *
 * Revision History:
 *
 */


#include <ctype.h>
#include <stdio.h>
#include "str.h"
#include "sweep.h"
#include "swmsg.h"
#include "piipcfg.h"
#include "pidef.h"
#include "taskweb.h"
#include "weblib.h"



/*---------------------  Static Definitions -------------------------*/

/*---------------------  Static Classes  ----------------------------*/

/*---------------------  Static Variables  --------------------------*/

/*---------------------  Static Functions  --------------------------*/

/*---------------------  Export Variables  --------------------------*/

/*---------------------  Export Macros  -----------------------------*/

/*---------------------  Export Functions  --------------------------*/
// Convert ip string to dw. If invalid, return 0.
static UINT32 PIIPCONF_dwCvtIpStr(char* szIp) DIRECT_FUNTYPE_REENT
{
    UINT32  dwIp = 0;
    BYTE    byVal = 0;
    BYTE    byCnt = 0;

    while (*szIp)
    {
        if (*szIp == '.')
        {
            dwIp = (dwIp<<8) | byVal;
            byVal = 0;
            byCnt++;
        }
        else if (! isdigit(*szIp))
            return 0;
        else
        {
            byVal *= 10;
            if (byVal + toint(*szIp) < byVal)
                return 0;
            byVal += toint(*szIp);
        }
        szIp++;
    }
    if (byCnt != 3)
        return 0;

    return ((dwIp<<8) | byVal);
}

void PIIPCONF_vInitPage(SIpConfPageCfg* pSPageCfg_IpConf) DIRECT_FUNTYPE_REENT
{
    BYTE si;
    PIEEP_vGetCfgFromEep(EEP_ADDR_IP_CONF, EEP_SIZE_IP_CONF, (PBYTE)pSPageCfg_IpConf);

    // convert mac address to hex string
    for (si=0; si<6; si++)
        sprintf(pSPageCfg_IpConf->szMac+si*3, "%02bX:", NTZg_abyMyEthAddr[si]);
    pSPageCfg_IpConf->szMac[MAC_STRING_LEN] = 0;    // remove the last ":"
}

void PIIPCONF_vSetCfgToHW(SIpConfPageCfg* pSPageCfg_IpConf) DIRECT_FUNTYPE_REENT
{
    NTZg_dwMyIpAddr = PIIPCONF_dwCvtIpStr(pSPageCfg_IpConf->szIp);
    NTZg_dwMyNetmask = PIIPCONF_dwCvtIpStr(pSPageCfg_IpConf->szSubnet);
    NTZg_dwMyDefGateway = PIIPCONF_dwCvtIpStr(pSPageCfg_IpConf->szGateway);
}

void PIIPCONF_vSetHwFromEep(SIpConfPageCfg* pSPageCfg_IpConf) DIRECT_FUNTYPE_REENT
{
    PIIPCONF_vInitPage(pSPageCfg_IpConf);
    PIIPCONF_vSetCfgToHW(pSPageCfg_IpConf);
}

void PIIPCONF_vSetEepDefault(SIpConfPageCfg* pSPageCfg_IpConf) DIRECT_FUNTYPE_REENT
{
    STRvStrcpy(pSPageCfg_IpConf->szIp,      DEFAULT_IP_ADDR);
    STRvStrcpy(pSPageCfg_IpConf->szSubnet,  DEFAULT_SUBNET);
    STRvStrcpy(pSPageCfg_IpConf->szGateway, DEFAULT_GATEWAY);

    PIEEP_vSetCfgIntoEep((PBYTE)pSPageCfg_IpConf, EEP_ADDR_IP_CONF, EEP_SIZE_IP_CONF);
    PIEEP_vUpdateChecksum();
}

BYTE PIIPCONF_bySavePage(SIpConfPageCfg* pSPageCfg_IpConf) DIRECT_FUNTYPE_REENT
{
    if (! PIIPCONF_dwCvtIpStr(pSPageCfg_IpConf->szIp))
        return IPCONF_OP_INVALID_IP;
    if (! PIIPCONF_dwCvtIpStr(pSPageCfg_IpConf->szSubnet))
        return IPCONF_OP_INVALID_SUBNET;
    if (! PIIPCONF_dwCvtIpStr(pSPageCfg_IpConf->szGateway))
        return IPCONF_OP_INVALID_GATEWAY;

    PIEEP_vSetCfgIntoEep((PBYTE)pSPageCfg_IpConf, EEP_ADDR_IP_CONF, EEP_SIZE_IP_CONF);
    PIEEP_vUpdateChecksum();

    PIIPCONF_vSetCfgToHW(pSPageCfg_IpConf);

    // after ip changed, auto logout web page
    *WEBg_szLoginID = 0;

    return OP_OK;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -