📄 ospf_nvrmutil.c
字号:
/* nvrmutil.c *//* Copyright 2003 Wind River Systems, Inc. *//*modification history--------------------o1b,14aug03,kkz Changed nvram to ospf_nvram01a,29may03,agi created (ported from RWOS)*//* includes */#include "stdio.h"#include "string.h"#include "stdarg.h"#include "ospf.h"extern OSPF_NVRAM_CLASS ospf_nvram;extern void nvram_printf (const char *cptr_format, ...);/****************************************************************************/static ULONG get_decimal_value (char *cptr_value){ sscanf (cptr_value,"%011lu",(ULONG *) &ospf_nvram.value[0]); return (*((ULONG *) &ospf_nvram.value[0]));}/****************************************************************************/void ospf_set_ulong_decimal_value (char *cptr_value_string,ULONG offset,ULONG ulptr_base){ *(ULONG *) (offset + ulptr_base) = (ULONG) get_decimal_value (cptr_value_string);}/****************************************************************************/static ULONG convert_4_bytes_to_ulong ( BYTE byte_1, BYTE byte_2, BYTE byte_3, BYTE byte_4) { ULONG return_value; ULONG byte_array[4]; byte_array[0] = byte_1; byte_array[1] = byte_2; byte_array[2] = byte_3; byte_array[3] = byte_4; return_value = (ULONG) byte_array[0]; return_value |= (ULONG) (byte_array[1] << 8); return_value |= (ULONG) (byte_array[2] << 16); return_value |= (ULONG) (byte_array[3] << 24); return (return_value); }/****************************************************************************/static USHORT get_port_number_and_string (char *cptr_port_number_and_value,char *return_string){ ULONG port_number; *return_string = (char) 0x00; sscanf (cptr_port_number_and_value,"%02u,%s",(int *) &port_number,return_string); return ((USHORT) port_number);}/****************************************************************************/BOOLEAN nvram_is_parameter_enabled (char *cptr_parameter_string){ if (strstr((const char *)ospf_strlwr (cptr_parameter_string), (const char *)"enable") != NULL) { return (TRUE); } else { return (FALSE); }}/**************************************************************************/void ospf_set_variable_port_and_enable (char *cptr_value_string,ULONG vptr_parameter_1, ULONG ulptr_parameter_2,ULONG size_of_parameter){ USHORT port_number; char enable_string[20]; port_number = get_port_number_and_string (cptr_value_string,&enable_string[0]); if (nvram_is_parameter_enabled (enable_string) == TRUE) { *(BYTE_ENUM (BOOLEAN) *)(vptr_parameter_1 + ulptr_parameter_2 + (port_number * size_of_parameter)) = TRUE; } else { *(BYTE_ENUM (BOOLEAN) *)(vptr_parameter_1 + ulptr_parameter_2 + (port_number * size_of_parameter)) = FALSE; }}/****************************************************************************/void ospf_set_enum_enable (char *cptr_value_string,ULONG offset,ULONG ulptr_base){ if (nvram_is_parameter_enabled (cptr_value_string) == TRUE) { *(BOOLEAN *) (ulptr_base + offset) = TRUE; } else { *(BOOLEAN *) (ulptr_base + offset) = FALSE; }}#if (_BYTE_ORDER == _BIG_ENDIAN)/****************************************************************************/static ULONG get_port_number_and_value (char *cptr_port_number_and_value,USHORT *usptr_port_number){ ULONG port_number; memset (&ospf_nvram.value[0],(int) NULL,9); sscanf (cptr_port_number_and_value,"%02u,%08lu",(int *) &port_number,(ULONG *) &ospf_nvram.value[0]); *usptr_port_number = (USHORT)port_number; return (*((ULONG *) &ospf_nvram.value[0]));}#else/****************************************************************************/static ULONG get_port_number_and_value (char *cptr_port_number_and_value,USHORT *usptr_port_number){ USHORT port_number[2]; memset (&ospf_nvram.value[0],(int) NULL,9); sscanf (cptr_port_number_and_value,"%02u,%08lu",(int *) &port_number[0],(ULONG *) &ospf_nvram.value[0]); *usptr_port_number = port_number[0]; return (*((ULONG *) &ospf_nvram.value[0]));}#endif/****************************************************************************/void ospf_set_variable_port_and_ushort_decimal_value (char *cptr_value_string,ULONG vptr_parameter_1, ULONG ulptr_parameter_2,ULONG size_of_parameter){ USHORT port_number; USHORT port_value; port_value = (USHORT) get_port_number_and_value (cptr_value_string,&port_number); *(USHORT *)(vptr_parameter_1 + ulptr_parameter_2 + (port_number * size_of_parameter)) = port_value;}/****************************************************************************/void ospf_set_variable_port_and_ulong_decimal_value (char *cptr_value_string,ULONG vptr_parameter_1, ULONG ulptr_parameter_2,ULONG size_of_parameter){ USHORT port_number; ULONG port_value; port_value = get_port_number_and_value (cptr_value_string,&port_number); *(ULONG *)(vptr_parameter_1 + ulptr_parameter_2 + (port_number * size_of_parameter)) = port_value;}/****************************************************************************/void ospf_set_variable_port_and_ip_address (char *cptr_ip_address_string,ULONG vptr_parameter_1, ULONG ulptr_parameter_2,ULONG size_of_parameter){ USHORT port_number; char ip_address_string[20]; ULONG ip_address; ULONG tmp0,tmp1,tmp2,tmp3; port_number = get_port_number_and_string (cptr_ip_address_string,&ip_address_string[0]); sscanf (&ip_address_string[0],"%03lu.%03lu.%03lu.%03lu",&tmp0,&tmp1,&tmp2,&tmp3); ip_address = convert_4_bytes_to_ulong ((BYTE) tmp3, (BYTE) tmp2, (BYTE) tmp1, (BYTE) tmp0); memcpy ((ULONG *)(vptr_parameter_1 + ulptr_parameter_2 + (port_number * size_of_parameter)),&ip_address,sizeof (ULONG));}/****************************************************************************/void ospf_set_ip_address (char *cptr_ip_address_string,ULONG offset,ULONG ulptr_base){ ULONG ip_address; ULONG tmp0,tmp1,tmp2,tmp3; sscanf (cptr_ip_address_string,"%03lu.%03lu.%03lu.%03lu", &tmp0, &tmp1, &tmp2, &tmp3); ip_address = convert_4_bytes_to_ulong ((BYTE) tmp3, (BYTE) tmp2, (BYTE) tmp1, (BYTE) tmp0); memcpy ((ULONG *)(offset + ulptr_base),&ip_address,sizeof (ULONG));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -