|
|
|||
File indexing completed on 2026-09-20 09:20:26
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) 2008 Sun Microsystems, Inc. All rights reserved. 0015 * Copyright (c) 2013 Cisco Systems, Inc. All rights reserved. 0016 * Copyright (c) 2016-2020 Intel, Inc. All rights reserved. 0017 * Copyright (c) 2021-2025 Nanook Consulting All rights reserved. 0018 * $COPYRIGHT$ 0019 * 0020 * Additional copyrights may follow 0021 * 0022 * $HEADER$ 0023 */ 0024 0025 /* @file */ 0026 0027 #ifndef PMIX_PIF_UTIL_ 0028 #define PMIX_PIF_UTIL_ 0029 0030 #include "src/include/pmix_config.h" 0031 0032 #ifdef HAVE_SYS_TYPES_H 0033 # include <sys/types.h> 0034 #endif 0035 #ifdef HAVE_SYS_SOCKET_H 0036 # include <sys/socket.h> 0037 #endif 0038 #ifdef HAVE_NETINET_IN_H 0039 # include <netinet/in.h> 0040 #endif 0041 0042 #include "pmix_common.h" 0043 #include "src/class/pmix_list.h" 0044 0045 #define PMIX_IF_NAMESIZE 256 0046 0047 BEGIN_C_DECLS 0048 0049 #define PMIX_PIF_FORMAT_ADDR(n) \ 0050 (((n) >> 24) & 0x000000FF), (((n) >> 16) & 0x000000FF), (((n) >> 8) & 0x000000FF), \ 0051 ((n) &0x000000FF) 0052 0053 #define PMIX_PIF_ASSEMBLE_FABRIC(n1, n2, n3, n4) \ 0054 (((n1) << 24) & 0xFF000000) | (((n2) << 16) & 0x00FF0000) | (((n3) << 8) & 0x0000FF00) \ 0055 | ((n4) &0x000000FF) 0056 0057 typedef struct pmix_pif_t { 0058 pmix_list_item_t super; 0059 char if_name[PMIX_IF_NAMESIZE + 1]; 0060 int if_index; 0061 uint16_t if_kernel_index; 0062 uint16_t af_family; 0063 int if_flags; 0064 int if_speed; 0065 struct sockaddr_storage if_addr; 0066 uint32_t if_mask; 0067 uint32_t if_bandwidth; 0068 uint8_t if_mac[6]; 0069 int ifmtu; /* Can't use if_mtu because of a 0070 #define collision on some BSDs */ 0071 } pmix_pif_t; 0072 PMIX_EXPORT PMIX_CLASS_DECLARATION(pmix_pif_t); 0073 0074 0075 /* "global" list of available interfaces */ 0076 PMIX_EXPORT extern pmix_list_t pmix_if_list; 0077 0078 /* global flags */ 0079 PMIX_EXPORT extern bool pmix_if_do_not_resolve; 0080 0081 /** 0082 * Lookup an interface by address and return its name. 0083 * 0084 * @param if_addr (IN) Interface address (hostname or dotted-quad) 0085 * @param if_name (OUT) Interface name buffer 0086 * @param size (IN) Interface name buffer size 0087 */ 0088 PMIX_EXPORT int pmix_ifaddrtoname(const char *if_addr, char *if_name, int size); 0089 0090 /** 0091 * Lookup an interface by name and return its pmix_list index. 0092 * 0093 * @param if_name (IN) Interface name 0094 * @return Interface pmix_list index 0095 */ 0096 PMIX_EXPORT int pmix_ifnametoindex(const char *if_name); 0097 0098 /** 0099 * Lookup an interface by name and return its kernel index. 0100 * 0101 * @param if_name (IN) Interface name 0102 * @return Interface kernel index 0103 */ 0104 PMIX_EXPORT int16_t pmix_ifnametokindex(const char *if_name); 0105 0106 /* 0107 * Attempt to resolve an address (given as either IPv4/IPv6 string 0108 * or hostname) and return the kernel index of the interface 0109 * that is on the same network as the specified address 0110 */ 0111 PMIX_EXPORT int16_t pmix_ifaddrtokindex(const char *if_addr); 0112 0113 /** 0114 * Lookup an interface by pmix_list index and return its kernel index. 0115 * 0116 * @param if_name (IN) Interface pmix_list index 0117 * @return Interface kernel index 0118 */ 0119 PMIX_EXPORT int pmix_ifindextokindex(int if_index); 0120 0121 /** 0122 * Returns the number of available interfaces. 0123 */ 0124 PMIX_EXPORT int pmix_ifcount(void); 0125 0126 /** 0127 * Returns the index of the first available interface. 0128 */ 0129 PMIX_EXPORT int pmix_ifbegin(void); 0130 0131 /** 0132 * Lookup the current position in the interface list by 0133 * index and return the next available index (if it exists). 0134 * 0135 * @param if_index Returns the next available index from the 0136 * current position. 0137 */ 0138 PMIX_EXPORT int pmix_ifnext(int if_index); 0139 0140 /** 0141 * Lookup an interface by index and return its name. 0142 * 0143 * @param if_index (IN) Interface index 0144 * @param if_name (OUT) Interface name buffer 0145 * @param size (IN) Interface name buffer size 0146 */ 0147 PMIX_EXPORT int pmix_ifindextoname(int if_index, char *if_name, int); 0148 0149 /** 0150 * Lookup an interface by kernel index and return its name. 0151 * 0152 * @param if_index (IN) Interface kernel index 0153 * @param if_name (OUT) Interface name buffer 0154 * @param size (IN) Interface name buffer size 0155 */ 0156 PMIX_EXPORT int pmix_ifkindextoname(int if_kindex, char *if_name, int); 0157 0158 /** 0159 * Lookup an interface by index and return its primary address. 0160 * 0161 * @param if_index (IN) Interface index 0162 * @param if_name (OUT) Interface address buffer 0163 * @param size (IN) Interface address buffer size 0164 */ 0165 PMIX_EXPORT int pmix_ifindextoaddr(int if_index, struct sockaddr *, unsigned int); 0166 PMIX_EXPORT int pmix_ifkindextoaddr(int if_kindex, struct sockaddr *if_addr, unsigned int length); 0167 0168 /** 0169 * Lookup an interface by index and return its network mask (in CIDR 0170 * notation -- NOT the actual netmask itself!). 0171 * 0172 * @param if_index (IN) Interface index 0173 * @param if_name (OUT) Interface address buffer 0174 * @param size (IN) Interface address buffer size 0175 */ 0176 PMIX_EXPORT int pmix_ifindextomask(int if_index, uint32_t *, int); 0177 0178 /** 0179 * Lookup an interface by index and return its MAC address. 0180 * 0181 * @param if_index (IN) Interface index 0182 * @param if_mac (OUT) Interface's MAC address 0183 */ 0184 PMIX_EXPORT int pmix_ifindextomac(int if_index, uint8_t if_mac[6]); 0185 0186 /** 0187 * Lookup an interface by index and return its MTU. 0188 * 0189 * @param if_index (IN) Interface index 0190 * @param if_mtu (OUT) Interface's MTU 0191 */ 0192 PMIX_EXPORT int pmix_ifindextomtu(int if_index, int *mtu); 0193 0194 /** 0195 * Lookup an interface by index and return its flags. 0196 * 0197 * @param if_index (IN) Interface index 0198 * @param if_flags (OUT) Interface flags 0199 */ 0200 PMIX_EXPORT int pmix_ifindextoflags(int if_index, uint32_t *); 0201 0202 /** 0203 * Determine if given hostname / IP address is a local address 0204 * 0205 * @param hostname (IN) Hostname (or stringified IP address) 0206 * @return true if \c hostname is local, false otherwise 0207 */ 0208 PMIX_EXPORT bool pmix_ifislocal(const char *hostname); 0209 0210 /** 0211 * Convert a dot-delimited network tuple to an IP address 0212 * 0213 * @param addr (IN) character string tuple 0214 * @param net (IN) Pointer to returned network address 0215 * @param mask (IN) Pointer to returned netmask 0216 * @return PMIX_SUCCESS if no problems encountered 0217 * @return PMIX_ERROR if data could not be released 0218 */ 0219 PMIX_EXPORT int pmix_iftupletoaddr(const char *addr, uint32_t *net, uint32_t *mask); 0220 0221 /** 0222 * Determine if given interface is loopback 0223 * 0224 * @param if_index (IN) Interface index 0225 */ 0226 PMIX_EXPORT bool pmix_ifisloopback(int if_index); 0227 0228 /* 0229 * Determine if a specified interface is included in a NULL-terminated argv array 0230 */ 0231 PMIX_EXPORT int pmix_ifmatches(int kidx, char **nets); 0232 0233 /* 0234 * Provide a list of strings that contain all known aliases for this node 0235 */ 0236 PMIX_EXPORT void pmix_ifgetaliases(char ***aliases); 0237 0238 END_C_DECLS 0239 0240 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|