[riot-notifications] [RIOT-OS/RIOT] netutils: add netutils_parse_hostname() (#16634)

Marian Buschsieweke notifications at github.com
Wed Jul 14 15:33:40 CEST 2021

@maribu commented on this pull request.

> +#include "net/utils.h"
+#include "net/sock/dns.h"
+/* get the next netif, returns true if there are more */
+static bool _netif_get(netif_t **current_netif)
+    netif_t *netif = *current_netif;
+    netif = netif_iter(netif);
+    *current_netif = netif;
+    return netif_iter(netif);
+int netutils_parse_hostname(const char *hostname, ipv6_addr_t *addr, netif_t **netif)

Note that the original proposal to just add an v6 to the function name has the advantage to allow symbols to be garbage collected when only the v4 or v6 flavor is ever called. Having an explicit family parameter can not as easily be optimized out.

>From the user point of view, writing `v6` takes less time than `AF_INET` or `AF_INET6`.

The only reason IMO an additional family parameter is better than separate functions is when `AF_UNSPEC` is supported (as @miri64 suggested). However, I don't think that this easily works with just a byte array, as the caller would still need to now what kind of address is returned. Making the family parameter in/out (`int *family`) would solve this, but that doesn't really sound convenient. The other solution coming to my mind is using something like `[struct sockaddr](https://api.riot-os.org/structsockaddr.html)` to store the address family along with the address. But I personally think that the sockaddr APIs increase complexity and contain quite a few footguns. So I'm personally in favor of simply adding the v6 postfix.

Also note: In both POSIX and standard C functions the out parameters come before the in parameters (except for file descriptors or handles, e.g. see memcpy, strcpy, recvfrom). IMO, C code should generally try to be consistent with this. (I have to admit that getaddrinfo is also breaking with this style, though.)

You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210714/6cb414ca/attachment.htm>

More information about the notifications mailing list