/* ****************************************************************************** * INTERPEAK SOURCE FILE * * Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_cmd.c,v $ $Revision: 1.15 $ * $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_cmd.c,v $ * $Author: hxie $ * $State: Exp $ $Locker: $ * * INTERPEAK_COPYRIGHT_STRING * Design and implementation by Kenneth Jonsson ****************************************************************************** */ /* **************************************************************************** * 1 DESCRIPTION **************************************************************************** */ /* **************************************************************************** * 2 CONFIGURATION **************************************************************************** */ #ifdef IPCOM_KERNEL #undef IPCOM_KERNEL #endif #include "iplite_config.h" /* **************************************************************************** * 3 INCLUDE FILES **************************************************************************** */ #define IPCOM_USE_CLIB_PROTO #include #include #include #include #include "iplite_h.h" #include "iplite_cmd.h" /* **************************************************************************** * 4 DEFINES **************************************************************************** */ /* **************************************************************************** * 5 TYPES **************************************************************************** */ /* **************************************************************************** * 6 EXTERN PROTOTYPES **************************************************************************** */ /* **************************************************************************** * 7 LOCAL PROTOTYPES **************************************************************************** */ /* **************************************************************************** * 8 DATA **************************************************************************** */ /* **************************************************************************** * 9 STATIC FUNCTIONS **************************************************************************** */ /* **************************************************************************** * 10 GLOBAL FUNCTIONS **************************************************************************** */ /* **************************************************************************** * 11 PUBLIC FUNCTIONS **************************************************************************** */ /* *=========================================================================== * iplite_netstat_key_to_str *=========================================================================== * Description: Converts the key to the string representation in map. * Parameters: map - The int to string map to use. * key - The protocol number. * Returns: The string represenstion. * */ IP_GLOBAL IP_CONST char * iplite_cmd_key_to_str(Iplite_cmd_int_str_map *map, int key) { int i; for (i = 0; map[i].key != -1; i++) if (map[i].key == key) return map[i].str; IP_PANIC(); return IP_NULL; } /* *=========================================================================== * iplite_netstat_key_to_str *=========================================================================== * Description: Converts the string representation in map to the numeric value. * Parameters: map - The int to string map to use. * key - The protocol number. * Returns: The string represenstion. * */ IP_GLOBAL int iplite_cmd_str_to_key(Iplite_cmd_int_str_map *map, IP_CONST char *str) { int i; for (i = 0; map[i].str != IP_NULL; i++) if (ipcom_strcmp(str, map[i].str) == 0) return map[i].key; return -1; } /* *=========================================================================== * iplite_cmd_hwaddr_to_str *=========================================================================== * Description: * Parameters: * Returns: * */ IP_GLOBAL char * iplite_cmd_hwaddr_to_str(Ip_u8 *hwaddr, Ip_size_t hwaddr_len, char *str, Ip_size_t str_len) { char tmp[4]; Ip_size_t n = 0; Ip_size_t i = 0; ipcom_sprintf (str, "%02X", hwaddr[n]); n++; i += 2; while (n < hwaddr_len && i < str_len - 1) { ipcom_sprintf (tmp, ":%02X", hwaddr[n]); ipcom_strcat (str, tmp); n++; i += 3; } return str; } IP_GLOBAL void iplite_cmd_init_addrs(void *msg, Ip_u32 addrs, struct Ip_sockaddr **sas) { int i; Ip_size_t offset = 0; for (i = 0; i < 8; i++) { if (IP_BIT_ISSET(addrs, 1 << i)) { sas[i] = (struct Ip_sockaddr *) &((Ip_u8 *) msg)[offset]; offset += IPCOM_SA_LEN_GET(sas[i]) ? IP_ROUNDUP(IPCOM_SA_LEN_GET(sas[i]), sizeof(Ip_u32)) : sizeof(Ip_u32); } else sas[i] = IP_NULL; } } /* **************************************************************************** * END OF FILE **************************************************************************** */