mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-01 20:29:00 +00:00
apps/net: add get iobinfo api
Obtain detailed IOB information by parsing the /proc/iobinfo file. Signed-off-by: meijian <meijian@xiaomi.com>
This commit is contained in:
parent
fb4f80665d
commit
9da2bc0696
4 changed files with 121 additions and 0 deletions
|
|
@ -52,6 +52,7 @@
|
|||
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <nuttx/mm/iob.h>
|
||||
#include <nuttx/net/netdev.h>
|
||||
#include <nuttx/net/netconfig.h>
|
||||
|
||||
|
|
@ -507,6 +508,10 @@ int netlib_getifstatistics(FAR const char *ifname,
|
|||
int netlib_check_ifconflict(FAR const char *ifname);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MM_IOB
|
||||
int netlib_get_iobinfo(FAR struct iob_stats_s *iob);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -149,6 +149,10 @@ if(CONFIG_NETUTILS_NETLIB)
|
|||
list(APPEND SRCS netlib_checkifconflict.c)
|
||||
endif()
|
||||
|
||||
if(CONFIG_MM_IOB)
|
||||
list(APPEND SRCS netlib_getiobinfo.c)
|
||||
endif()
|
||||
|
||||
target_sources(apps PRIVATE ${SRCS})
|
||||
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -148,4 +148,8 @@ ifeq ($(CONFIG_NET_ARP_ACD),y)
|
|||
CSRCS += netlib_checkifconflict.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_MM_IOB),y)
|
||||
CSRCS += netlib_getiobinfo.c
|
||||
endif
|
||||
|
||||
include $(APPDIR)/Application.mk
|
||||
|
|
|
|||
108
netutils/netlib/netlib_getiobinfo.c
Normal file
108
netutils/netlib/netlib_getiobinfo.c
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
/****************************************************************************
|
||||
* apps/netutils/netlib/netlib_getiobinfo.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include "netutils/netlib.h"
|
||||
|
||||
#ifdef CONFIG_MM_IOB
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Determines the size of an intermediate buffer that must be large enough
|
||||
* to handle the longest line generated by this logic.
|
||||
*/
|
||||
|
||||
#define PROCFS_LINELEN 80
|
||||
#define PROCFS_IOB_PATH "/proc/iobinfo"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netlib_get_iobinfo
|
||||
*
|
||||
* Description:
|
||||
* Get the network iob info.
|
||||
*
|
||||
* Parameters:
|
||||
* iob The pointer to return iobinfo.
|
||||
*
|
||||
* Return:
|
||||
* 0 on success; a nagtive on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int netlib_get_iobinfo(FAR struct iob_stats_s *iob)
|
||||
{
|
||||
int ret = OK;
|
||||
FAR FILE *stream;
|
||||
char line[PROCFS_LINELEN];
|
||||
|
||||
stream = fopen(PROCFS_IOB_PATH, "r");
|
||||
if (stream == NULL)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Failed to open path:%s \n", PROCFS_IOB_PATH);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
/* Read ioninfo header and next is the data */
|
||||
|
||||
if (fgets(line, sizeof(line), stream) != NULL)
|
||||
{
|
||||
if (fgets(line, sizeof(line), stream) == NULL)
|
||||
{
|
||||
ret = -EINVAL;
|
||||
fclose(stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (sscanf(line, "%d %d %d %d", &iob->ntotal, &iob->nfree,
|
||||
&iob->nwait, &iob->nthrottle) <= 0)
|
||||
{
|
||||
ret = -errno;
|
||||
fclose(stream);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_MM_IOB */
|
||||
Loading…
Add table
Add a link
Reference in a new issue