netlib/route: add length for add/del route-func to reduce caller stack usage
Signed-off-by: meijian <meijian@xiaomi.com>
This commit is contained in:
parent
84333881d7
commit
a4b4fd16e9
3 changed files with 27 additions and 15 deletions
|
@ -101,15 +101,15 @@ extern "C"
|
|||
* netmask - Network mask defining the external network (required)
|
||||
* router - Router address that on our network that can forward to the
|
||||
* external network.
|
||||
* len - The address struct length.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; -1 on failure with the errno variable set appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int addroute(int sockfd, FAR struct sockaddr_storage *target,
|
||||
FAR struct sockaddr_storage *netmask,
|
||||
FAR struct sockaddr_storage *router);
|
||||
int addroute(int sockfd, FAR void *target, FAR void *netmask,
|
||||
FAR void *router, socklen_t len);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_delroute
|
||||
|
@ -122,14 +122,14 @@ int addroute(int sockfd, FAR struct sockaddr_storage *target,
|
|||
* sockfd - Any socket descriptor
|
||||
* target - Target address on the remote network (required)
|
||||
* netmask - Network mask defining the external network (required)
|
||||
* len - The address struct length.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; -1 on failure with the errno variable set appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int delroute(int sockfd, FAR struct sockaddr_storage *target,
|
||||
FAR struct sockaddr_storage *netmask);
|
||||
int delroute(int sockfd, FAR void *target, FAR void *netmask, socklen_t len);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdint.h>
|
||||
|
@ -47,24 +48,29 @@
|
|||
* netmask - Network mask defining the external network (required)
|
||||
* router - Router address that on our network that can forward to the
|
||||
* external network.
|
||||
* len - The address struct length.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; -1 on failure with the errno variable set appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int addroute(int sockfd, FAR struct sockaddr_storage *target,
|
||||
FAR struct sockaddr_storage *netmask,
|
||||
FAR struct sockaddr_storage *router)
|
||||
int addroute(int sockfd, FAR void *target, FAR void *netmask,
|
||||
FAR void *router, socklen_t len)
|
||||
{
|
||||
struct rtentry entry;
|
||||
|
||||
if (len < sizeof(struct in_addr) || len > sizeof(struct sockaddr_storage))
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Set up the rtentry structure */
|
||||
|
||||
memset(&entry, 0, sizeof(struct rtentry));
|
||||
memcpy(&entry.rt_dst, target, sizeof(struct sockaddr_storage));
|
||||
memcpy(&entry.rt_genmask, netmask, sizeof(struct sockaddr_storage));
|
||||
memcpy(&entry.rt_gateway, router, sizeof(struct sockaddr_storage));
|
||||
memcpy(&entry.rt_dst, target, len);
|
||||
memcpy(&entry.rt_genmask, netmask, len);
|
||||
memcpy(&entry.rt_gateway, router, len);
|
||||
|
||||
/* Then perform the ioctl */
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdint.h>
|
||||
|
@ -45,22 +46,27 @@
|
|||
* sockfd - Any socket descriptor
|
||||
* target - Target address on the remote network (required)
|
||||
* netmask - Network mask defining the external network (required)
|
||||
* len - The address struct length.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; -1 on failure with the errno variable set appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int delroute(int sockfd, FAR struct sockaddr_storage *target,
|
||||
FAR struct sockaddr_storage *netmask)
|
||||
int delroute(int sockfd, FAR void *target, FAR void *netmask, socklen_t len)
|
||||
{
|
||||
struct rtentry entry;
|
||||
|
||||
if (len < sizeof(struct in_addr) || len > sizeof(struct sockaddr_storage))
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Set up the rtentry structure */
|
||||
|
||||
memset(&entry, 0, sizeof(struct rtentry));
|
||||
memcpy(&entry.rt_dst, target, sizeof(struct sockaddr_storage));
|
||||
memcpy(&entry.rt_genmask, netmask, sizeof(struct sockaddr_storage));
|
||||
memcpy(&entry.rt_dst, target, len);
|
||||
memcpy(&entry.rt_genmask, netmask, len);
|
||||
|
||||
/* Then perform the ioctl */
|
||||
|
||||
|
|
Loading…
Reference in a new issue