/************************************************************************ * NAME: fnet_netif_get_name * * DESCRIPTION: This function returns network interface name (e.g. "eth0", "loop"). *************************************************************************/ void fnet_netif_get_name( fnet_netif_desc_t netif_desc, char *name, unsigned char name_size ) { fnet_netif_t *netif = (fnet_netif_t *)netif_desc; if(netif) fnet_strncpy(name, netif->name, name_size); }
/************************************************************************ * NAME: fnet_fs_mount * * DESCRIPTION: Mounts a FS. *************************************************************************/ fnet_return_t fnet_fs_mount( fnet_char_t *fs_name, const fnet_char_t *mount_name, const void *arg ) { fnet_return_t result = FNET_ERR; struct fnet_fs_mount_point *mount_point = 0; struct fnet_fs * fs; fnet_index_t i; if(fs_name && mount_name) { fnet_os_mutex_lock(); fs = fnet_fs_find_name(fs_name); if(fs) { for(i=0U; i< FNET_CFG_FS_MOUNT_MAX; i++) { if(fnet_fs_mount_list[i].fs == 0) { mount_point = &fnet_fs_mount_list[i]; /* found free mount point */ break; } } if(mount_point) { if((fs->operations) && (fs->operations->mount)) { result = fs->operations->mount(arg); } else { result = FNET_OK; } if(result == FNET_OK) /* Mount is successful */ { mount_point->arg = arg; /* Fill mount info structure. */ mount_point->fs = fs; fnet_strncpy( mount_point->name, mount_name, FNET_CFG_FS_MOUNT_NAME_MAX+1U ); } } } fnet_os_mutex_unlock(); } return result; }
/************************************************************************ * NAME: fnet_inet_ntop_ip4 * * DESCRIPTION:The function converts IPv4 address * to presentation format (string). *************************************************************************/ static char *fnet_inet_ntop_ip4 ( const fnet_ip4_addr_t *addr, char *str, unsigned long str_len) { char tmp[FNET_IP4_ADDR_STR_SIZE]; int length; const unsigned char *ptr = (const unsigned char *) addr; length=fnet_snprintf(tmp, sizeof(tmp), "%d.%d.%d.%d", ptr[0], ptr[1], ptr[2], ptr[3]); if ((length <= 0) || (length >= str_len)) { return (FNET_NULL); } else { fnet_strncpy(str, tmp, (unsigned long)str_len); return (str); } }
/************************************************************************ * 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); }
static void fapp_set_cmd_image(fnet_shell_desc_t desc, char *value ) { (void)desc; fnet_strncpy( fapp_params_tftp_config.file_name, value, FAPP_PARAMS_TFTP_FILE_NAME_SIZE ); }
static void fapp_set_cmd_bootscript(fnet_shell_desc_t desc, char *value ) { (void)desc; fnet_strncpy( fapp_params_boot_config.script, value, FAPP_PARAMS_BOOT_SCRIPT_SIZE ); }