![]() |
|
|||
File indexing completed on 2025-02-22 10:47:27
0001 /* 0002 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana 0003 * University Research and Technology 0004 * Corporation. All rights reserved. 0005 * Copyright (c) 2004-2005 The University of Tennessee and The University 0006 * of Tennessee Research Foundation. All rights 0007 * reserved. 0008 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, 0009 * University of Stuttgart. All rights reserved. 0010 * Copyright (c) 2004-2005 The Regents of the University of California. 0011 * All rights reserved. 0012 * Copyright (c) 2007 Los Alamos National Security, LLC. All rights 0013 * reserved. 0014 * Copyright (c) 2017 Intel, Inc. All rights reserved. 0015 * Copyright (c) 2021-2022 Nanook Consulting. All rights reserved. 0016 * $COPYRIGHT$ 0017 * 0018 * Additional copyrights may follow 0019 * 0020 * $HEADER$ 0021 */ 0022 0023 /* @file */ 0024 0025 #ifndef PMIX_UTIL_NET_H 0026 #define PMIX_UTIL_NET_H 0027 0028 #include "src/include/pmix_config.h" 0029 0030 #ifdef HAVE_SYS_TYPES_H 0031 # include <sys/types.h> 0032 #endif 0033 #ifdef HAVE_SYS_SOCKET_H 0034 # include <sys/socket.h> 0035 #endif 0036 #ifdef HAVE_NETINET_IN_H 0037 # include <netinet/in.h> 0038 #endif 0039 0040 #include "pmix_common.h" 0041 0042 BEGIN_C_DECLS 0043 0044 /** 0045 * Initialize the network helper subsystem 0046 * 0047 * Initialize the network helper subsystem. Should be called exactly 0048 * once for any process that will use any function in the network 0049 * helper subsystem. 0050 * 0051 * @retval PMIX_SUCCESS Success 0052 * @retval PMIX_ERR_TEMP_OUT_OF_RESOURCE Not enough memory for static 0053 * buffer creation 0054 */ 0055 PMIX_EXPORT int pmix_net_init(void); 0056 0057 /** 0058 * Finalize the network helper subsystem 0059 * 0060 * Finalize the network helper subsystem. Should be called exactly 0061 * once for any process that will use any function in the network 0062 * helper subsystem. 0063 * 0064 * @retval PMIX_SUCCESS Success 0065 */ 0066 PMIX_EXPORT int pmix_net_finalize(void); 0067 0068 /** 0069 * Calculate netmask in network byte order from CIDR notation 0070 * 0071 * @param prefixlen (IN) CIDR prefixlen 0072 * @return netmask in network byte order 0073 */ 0074 PMIX_EXPORT uint32_t pmix_net_prefix2netmask(uint32_t prefixlen); 0075 0076 /** 0077 * Determine if given IP address is in the localhost range 0078 * 0079 * Determine if the given IP address is in the localhost range 0080 * (127.0.0.0/8), meaning that it can't be used to connect to machines 0081 * outside the current host. 0082 * 0083 * @param addr struct sockaddr_in of IP address 0084 * @return true if \c addr is a localhost address, 0085 * false otherwise. 0086 */ 0087 PMIX_EXPORT bool pmix_net_islocalhost(const struct sockaddr *addr); 0088 0089 /** 0090 * Are we on the same network? 0091 * 0092 * For IPv6, we only need to check for /64, there are no other 0093 * local netmasks. 0094 * 0095 * @param addr1 struct sockaddr of address 0096 * @param addr2 struct sockaddr of address 0097 * @param prefixlen netmask (either CIDR or IPv6 prefixlen) 0098 * @return true if \c addr1 and \c addr2 are on the 0099 * same net, false otherwise. 0100 */ 0101 PMIX_EXPORT bool pmix_net_samenetwork(const struct sockaddr_storage *addr1, 0102 const struct sockaddr_storage *addr2, 0103 uint32_t prefixlen); 0104 0105 /** 0106 * Is the given address a link-local IPv6 address? Returns false for IPv4 0107 * address. 0108 * 0109 * @param addr address as struct sockaddr 0110 * @return true, if \c addr is IPv6 link-local, false otherwise 0111 */ 0112 PMIX_EXPORT bool pmix_net_addr_isipv6linklocal(const struct sockaddr *addr); 0113 0114 /** 0115 * Is the given address a public IPv4 address? Returns false for IPv6 0116 * address. 0117 * 0118 * @param addr address as struct sockaddr 0119 * @return true, if \c addr is IPv4 public, false otherwise 0120 */ 0121 PMIX_EXPORT bool pmix_net_addr_isipv4public(const struct sockaddr *addr); 0122 0123 /** 0124 * Get string version of address 0125 * 0126 * Return the un-resolved address in a string format. The string will 0127 * be returned in a per-thread static buffer and should not be freed 0128 * by the user. 0129 * 0130 * @param addr struct sockaddr of address 0131 * @return literal representation of \c addr 0132 */ 0133 PMIX_EXPORT char *pmix_net_get_hostname(const struct sockaddr *addr); 0134 0135 /** 0136 * Get port number from struct sockaddr 0137 * 0138 * Return the port number (as an integr) from either a struct 0139 * sockaddr_in or a struct sockaddr_in6. 0140 * 0141 * @param addr struct sockaddr containing address 0142 * @return port number from \addr 0143 */ 0144 PMIX_EXPORT int pmix_net_get_port(const struct sockaddr *addr); 0145 0146 /** 0147 * Test if a string is actually an IP address 0148 * 0149 * Returns true if the string is of IPv4 or IPv6 address form 0150 */ 0151 PMIX_EXPORT bool pmix_net_isaddr(const char *name); 0152 0153 END_C_DECLS 0154 0155 #endif /* PMIX_UTIL_NET_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |