/************************************************************************ * NAME: fnet_mac_to_str * * DESCRIPTION: Converts MAC address to an null-terminated string. *************************************************************************/ void fnet_mac_to_str( fnet_mac_addr_t addr, char *str_mac ) { unsigned char *p; p = (unsigned char *)addr; fnet_sprintf(str_mac, "%02X:%02X:%02X:%02X:%02X:%02X", p[0], p[1], p[2], p[3], p[4], p[5]); }
/************************************************************************ * NAME: fnet_mac_to_str * * DESCRIPTION: Converts MAC address to an null-terminated string. *************************************************************************/ fnet_char_t *fnet_mac_to_str( const fnet_mac_addr_t addr, fnet_char_t *str_mac ) { fnet_uint8_t *p; if(str_mac) { p = (fnet_uint8_t *)addr; fnet_sprintf(str_mac, "%02X:%02X:%02X:%02X:%02X:%02X", p[0], p[1], p[2], p[3], p[4], p[5]); } return str_mac; }
/************************************************************************ * NAME: fapp_fs_cd_cmd * * DESCRIPTION: Change the current directory. *************************************************************************/ static void fapp_fs_cd_cmd( fnet_shell_desc_t desc, fnet_index_t argc, fnet_char_t ** argv ) { FNET_FS_DIR dir; fnet_char_t *path = argv[1]; fnet_char_t *path_end; fnet_size_t size_cd = fnet_strlen (fapp_fs_current_path); fnet_size_t size_path; fnet_char_t splitter[] = {FNET_FS_SPLITTER,'\0'}; FNET_COMP_UNUSED_ARG(argc); if (*path != FNET_FS_SPLITTER) /* Realative path.*/ { /* Add splitter if not yet.*/ if(fapp_fs_current_path[size_cd-1U] != FNET_FS_SPLITTER) { fnet_strncat( &fapp_fs_current_path[0], splitter, FAPP_FS_DIR_PATH_MAX); } fnet_strncat( &fapp_fs_current_path[0], path, FAPP_FS_DIR_PATH_MAX); path = fapp_fs_current_path; } else /* Full path. */ { /* Strip possible repetitive leading slashes. */ while ((path[0] == FNET_FS_SPLITTER) && (path[1] == FNET_FS_SPLITTER)) { path++; } } /* Strip possible ending slashes. */ if((size_path = fnet_strlen(path)) > 0U) { path_end = &path[size_path - 1U]; while(*path_end == FNET_FS_SPLITTER) { *path_end = '\0'; path_end--; } } /* Open dir. */ dir = fnet_fs_opendir(path); if (dir) { /* Update cur path. */ fnet_strncpy( &fapp_fs_current_path[0], path, FAPP_FS_DIR_PATH_MAX); if(fapp_fs_current_path[0] == '\0') /* root dir */ { fnet_strncat( &fapp_fs_current_path[0], splitter, FAPP_FS_DIR_PATH_MAX); } /* Change shell prompt. */ fnet_sprintf( FAPP_FS_PROMPT_STR, "%s%s%s", &FAPP_FS_PROMPT_STR_HEADER[0], &fapp_fs_current_path[0], &FAPP_FS_PROMPT_STR_TRAILER[0]); /* Close dir. */ fnet_fs_closedir(dir); } else { /* Restore cur path. */ fapp_fs_current_path[size_cd] = '\0'; fnet_shell_println(desc, FAPP_FS_CD_ERR, argv[1]); } }
static char *fnet_inet_ntop_ip6 (const fnet_ip6_addr_t *addr, char *str, unsigned long str_len) { char tmp[FNET_IP6_ADDR_STR_SIZE]; char *tp; struct { int base, len; } best, cur; unsigned long words[16 / 2]; int i; /* * Copy the input (bytewise) array into a wordwise array. * Find the longest run of 0x00's in addr[] for :: shorthanding. */ fnet_memset_zero(words, sizeof(words)); for (i = 0; i < 16; i++) { words[i / 2] |= ((unsigned long)addr->addr[i] << ((1 - (i % 2)) << 3)); } best.base = -1; best.len = 0; cur.base = -1; cur.len = 0; for (i = 0; i < (16 / 2); i++) { if (words[i] == 0) { if (cur.base == -1) { cur.base = i; cur.len = 1; } else cur.len++; } else { if (cur.base != -1) { if (best.base == -1 || cur.len > best.len) best = cur; cur.base = -1; } } } if (cur.base != -1) { if (best.base == -1 || cur.len > best.len) best = cur; } if (best.base != -1 && best.len < 2) best.base = -1; /* Format the result. */ tp = tmp; for (i = 0; i < (16 / 2); i++) { /* Are we inside the best run of 0x00's? */ if (best.base != -1 && i >= best.base && i < (best.base + best.len)) { if (i == best.base) *tp++ = ':'; continue; } /* Are we following an initial run of 0x00s or any real hex? */ if (i != 0) *tp++ = ':'; tp += fnet_sprintf(tp, "%x", words[i]); } /* Was it a trailing run of 0x00's? */ if (best.base != -1 && (best.base + best.len) == (16 / 2)) *tp++ = ':'; *tp++ = '\0'; /* Check for overflow, copy, and we're done. */ if ((int)(tp - tmp) > str_len) { return (FNET_NULL); } fnet_strncpy(str, tmp, (unsigned long)str_len); return (str); }