1 /* 2 * Replacement implementation of getnameinfo. 3 * 4 * This is an implementation of the getnameinfo function for systems that lack 5 * it, so that code can use getnameinfo always. It provides IPv4 support 6 * only; for IPv6 support, a native getnameinfo implementation is required. 7 * 8 * This file should generally be included by way of portable/socket.h rather 9 * than directly. 10 * 11 * The canonical version of this file is maintained in the rra-c-util package, 12 * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>. 13 * 14 * Written by Russ Allbery <eagle@eyrie.org> 15 * Copyright 2005, 2007, 2020 Russ Allbery <eagle@eyrie.org> 16 * Copyright 2008, 2010-2011 17 * The Board of Trustees of the Leland Stanford Junior University 18 * 19 * Copying and distribution of this file, with or without modification, are 20 * permitted in any medium without royalty provided the copyright notice and 21 * this notice are preserved. This file is offered as-is, without any 22 * warranty. 23 * 24 * SPDX-License-Identifier: FSFAP 25 */ 26 27 #ifndef PORTABLE_GETNAMEINFO_H 28 #define PORTABLE_GETNAMEINFO_H 1 29 30 #include "config.h" 31 #include "portable/macros.h" 32 33 /* Skip this entire file if a system getaddrinfo was detected. */ 34 #if !HAVE_GETNAMEINFO 35 36 /* OpenBSD likes to have sys/types.h included before sys/socket.h. */ 37 /* clang-format off */ 38 # include <sys/types.h> 39 # include <sys/socket.h> 40 /* clang-format on */ 41 42 /* Constants for flags from RFC 3493, combined with binary or. */ 43 # define NI_NOFQDN 0x0001 44 # define NI_NUMERICHOST 0x0002 45 # define NI_NAMEREQD 0x0004 46 # define NI_NUMERICSERV 0x0008 47 # define NI_DGRAM 0x0010 48 49 /* 50 * Maximum length of hostnames and service names. Our implementation doesn't 51 * use these values, so they're taken from Linux. They're provided just for 52 * code that uses them to size buffers. 53 */ 54 # ifndef NI_MAXHOST 55 # define NI_MAXHOST 1025 56 # endif 57 # ifndef NI_MAXSERV 58 # define NI_MAXSERV 32 59 # endif 60 61 BEGIN_DECLS 62 63 /* Function prototypes. */ 64 int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *node, 65 socklen_t nodelen, char *service, socklen_t servicelen, 66 int flags); 67 68 END_DECLS 69 70 #endif /* !HAVE_GETNAMEINFO */ 71 #endif /* !PORTABLE_GETNAMEINFO_H */ 72