|
| 1 | +/**************************************************************************** |
| 2 | + * apps/netutils/netlib/netlib_delipv4dnsaddr.c |
| 3 | + * |
| 4 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 5 | + * contributor license agreements. See the NOTICE file distributed with |
| 6 | + * this work for additional information regarding copyright ownership. The |
| 7 | + * ASF licenses this file to you under the Apache License, Version 2.0 (the |
| 8 | + * "License"); you may not use this file except in compliance with the |
| 9 | + * License. You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 16 | + * License for the specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + * |
| 19 | + ****************************************************************************/ |
| 20 | + |
| 21 | +/**************************************************************************** |
| 22 | + * Included Files |
| 23 | + ****************************************************************************/ |
| 24 | + |
| 25 | +#include <nuttx/config.h> |
| 26 | + |
| 27 | +#include <sys/socket.h> |
| 28 | +#include <stdint.h> |
| 29 | +#include <string.h> |
| 30 | +#include <errno.h> |
| 31 | + |
| 32 | +#include <netinet/in.h> |
| 33 | +#include <nuttx/net/dns.h> |
| 34 | + |
| 35 | +#include "netutils/netlib.h" |
| 36 | + |
| 37 | +#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NETDB_DNSCLIENT) |
| 38 | + |
| 39 | +/**************************************************************************** |
| 40 | + * Public Functions |
| 41 | + ****************************************************************************/ |
| 42 | + |
| 43 | +/**************************************************************************** |
| 44 | + * Name: netlib_del_ipv4dnsaddr |
| 45 | + * |
| 46 | + * Description: |
| 47 | + * Remove a DNS server IPv4 address from the list by address |
| 48 | + * |
| 49 | + * Parameters: |
| 50 | + * inaddr The address to remove |
| 51 | + * |
| 52 | + * Return: |
| 53 | + * Zero (OK) is returned on success; A negated errno value is returned |
| 54 | + * on failure. |
| 55 | + * |
| 56 | + ****************************************************************************/ |
| 57 | + |
| 58 | +int netlib_del_ipv4dnsaddr(FAR const struct in_addr *inaddr) |
| 59 | +{ |
| 60 | + struct sockaddr_in addr; |
| 61 | + int ret = -EINVAL; |
| 62 | + |
| 63 | + if (inaddr) |
| 64 | + { |
| 65 | + addr.sin_family = AF_INET; |
| 66 | + addr.sin_port = 0; |
| 67 | + memcpy(&addr.sin_addr, inaddr, sizeof(struct in_addr)); |
| 68 | + bzero(&addr.sin_zero, sizeof(addr.sin_zero)); |
| 69 | + |
| 70 | + ret = dns_del_nameserver((FAR const struct sockaddr *)&addr, |
| 71 | + sizeof(struct sockaddr_in)); |
| 72 | + } |
| 73 | + |
| 74 | + return ret; |
| 75 | +} |
| 76 | + |
| 77 | +/**************************************************************************** |
| 78 | + * Name: netlib_del_ipv4dnsaddr_by_index |
| 79 | + * |
| 80 | + * Description: |
| 81 | + * Remove a DNS server IPv4 address from the list by index (0-based) |
| 82 | + * |
| 83 | + * Parameters: |
| 84 | + * index: The index of the DNS server to remove (0=first, 1=second, etc.) |
| 85 | + * |
| 86 | + * Return: |
| 87 | + * Zero (OK) is returned on success; A negated errno value is returned |
| 88 | + * on failure. |
| 89 | + * |
| 90 | + ****************************************************************************/ |
| 91 | + |
| 92 | +int netlib_del_ipv4dnsaddr_by_index(int index) |
| 93 | +{ |
| 94 | + return dns_del_nameserver_by_index(index); |
| 95 | +} |
| 96 | + |
| 97 | +#endif /* CONFIG_NET_IPv4 && CONFIG_NETDB_DNSCLIENT */ |
0 commit comments