2015-10-03 01:43:18 +02:00
|
|
|
/****************************************************************************
|
2018-05-29 21:21:26 +02:00
|
|
|
* libs/libc/net/lib_delroute.c
|
2013-10-02 18:51:48 +02:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* 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
|
2013-10-02 18:51:48 +02:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-10-02 18:51:48 +02:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* 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.
|
2013-10-02 18:51:48 +02:00
|
|
|
*
|
2015-10-03 01:43:18 +02:00
|
|
|
****************************************************************************/
|
2013-10-02 18:51:48 +02:00
|
|
|
|
2015-10-03 01:43:18 +02:00
|
|
|
/****************************************************************************
|
2013-10-02 18:51:48 +02:00
|
|
|
* Included Files
|
2015-10-03 01:43:18 +02:00
|
|
|
****************************************************************************/
|
2013-10-02 18:51:48 +02:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2024-06-18 14:24:56 +02:00
|
|
|
#include <errno.h>
|
2013-10-02 18:51:48 +02:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <stdint.h>
|
2013-10-05 20:05:51 +02:00
|
|
|
#include <string.h>
|
2013-10-02 18:51:48 +02:00
|
|
|
#include <net/route.h>
|
|
|
|
|
2015-10-03 01:43:18 +02:00
|
|
|
/****************************************************************************
|
2015-10-03 00:30:35 +02:00
|
|
|
* Public Functions
|
2015-10-03 01:43:18 +02:00
|
|
|
****************************************************************************/
|
2013-10-02 18:51:48 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: net_delroute
|
2013-10-02 18:51:48 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Add a new route to the routing table. This is just a convenience
|
|
|
|
* wrapper for the SIOCADDRT ioctl call.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-10-02 18:51:48 +02:00
|
|
|
* sockfd - Any socket descriptor
|
2013-10-05 20:05:51 +02:00
|
|
|
* target - Target address on the remote network (required)
|
|
|
|
* netmask - Network mask defining the external network (required)
|
2024-06-18 14:24:56 +02:00
|
|
|
* len - The address struct length.
|
2013-10-02 18:51:48 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success; -1 on failure with the errno variable set appropriately.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2024-06-18 14:24:56 +02:00
|
|
|
int delroute(int sockfd, FAR void *target, FAR void *netmask, socklen_t len)
|
2013-10-02 18:51:48 +02:00
|
|
|
{
|
|
|
|
struct rtentry entry;
|
|
|
|
|
2024-06-18 14:24:56 +02:00
|
|
|
if (len < sizeof(struct in_addr) || len > sizeof(struct sockaddr_storage))
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-10-02 18:51:48 +02:00
|
|
|
/* Set up the rtentry structure */
|
|
|
|
|
2013-10-05 20:05:51 +02:00
|
|
|
memset(&entry, 0, sizeof(struct rtentry));
|
2024-06-18 14:24:56 +02:00
|
|
|
memcpy(&entry.rt_dst, target, len);
|
|
|
|
memcpy(&entry.rt_genmask, netmask, len);
|
2013-10-02 18:51:48 +02:00
|
|
|
|
|
|
|
/* Then perform the ioctl */
|
|
|
|
|
|
|
|
return ioctl(sockfd, SIOCDELRT, (unsigned long)((uintptr_t)&entry));
|
|
|
|
}
|