2004-01-14 21:24:30 +03:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2007-05-17 05:17:59 +04:00
|
|
|
* Copyright (c) 2007 Los Alamos National Security, LLC. All rights
|
|
|
|
* reserved.
|
2008-11-05 21:45:42 +03:00
|
|
|
* Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-01-14 21:24:30 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2007-05-17 05:17:59 +04:00
|
|
|
/* @file */
|
|
|
|
|
2005-07-04 05:36:20 +04:00
|
|
|
#ifndef OPAL_IF_UTIL_
|
|
|
|
#define OPAL_IF_UTIL_
|
2004-01-14 21:24:30 +03:00
|
|
|
|
2009-03-04 18:35:54 +03:00
|
|
|
#include "opal_config.h"
|
|
|
|
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
2004-01-15 20:43:54 +03:00
|
|
|
#include <sys/types.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
2004-01-15 20:43:54 +03:00
|
|
|
#include <sys/socket.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2007-04-25 05:55:40 +04:00
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
|
2008-11-05 21:45:42 +03:00
|
|
|
#ifndef IF_NAMESIZE
|
|
|
|
#define IF_NAMESIZE 32
|
|
|
|
#endif
|
|
|
|
|
2007-04-25 23:08:07 +04:00
|
|
|
BEGIN_C_DECLS
|
2004-01-15 20:43:54 +03:00
|
|
|
|
2009-09-22 04:53:54 +04:00
|
|
|
#define OPAL_IF_FORMAT_ADDR(n) \
|
|
|
|
(((n) >> 24) & 0x000000FF), (((n) >> 16) & 0x000000FF), \
|
|
|
|
(((n) >> 8) & 0x000000FF), ((n) & 0x000000FF)
|
|
|
|
|
2009-10-09 19:24:41 +04:00
|
|
|
#define OPAL_IF_ASSEMBLE_NETWORK(n1, n2, n3, n4) \
|
|
|
|
(((n1) << 24) & 0xFF000000) | \
|
|
|
|
(((n2) << 16) & 0x00FF0000) | \
|
|
|
|
(((n3) << 8) & 0x0000FF00) | \
|
|
|
|
( (n4) & 0x000000FF)
|
|
|
|
|
2004-01-14 21:24:30 +03:00
|
|
|
/**
|
|
|
|
* Lookup an interface by name and return its primary address.
|
|
|
|
*
|
|
|
|
* @param if_name (IN) Interface name
|
|
|
|
* @param if_addr (OUT) Interface address buffer
|
|
|
|
* @param size (IN) Interface address buffer size
|
|
|
|
*/
|
2006-08-20 19:54:04 +04:00
|
|
|
OPAL_DECLSPEC int opal_ifnametoaddr(const char* if_name,
|
2007-05-17 05:17:59 +04:00
|
|
|
struct sockaddr* if_addr,
|
2007-04-25 05:55:40 +04:00
|
|
|
int size);
|
2004-01-14 21:24:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup an interface by address and return its name.
|
|
|
|
*
|
2004-11-01 17:18:30 +03:00
|
|
|
* @param if_addr (IN) Interface address (hostname or dotted-quad)
|
|
|
|
* @param if_name (OUT) Interface name buffer
|
2004-01-14 21:24:30 +03:00
|
|
|
* @param size (IN) Interface name buffer size
|
|
|
|
*/
|
2006-08-20 19:54:04 +04:00
|
|
|
OPAL_DECLSPEC int opal_ifaddrtoname(const char* if_addr,
|
2004-11-01 17:18:30 +03:00
|
|
|
char* if_name, int size);
|
2004-01-14 21:24:30 +03:00
|
|
|
|
|
|
|
/**
|
2007-04-25 05:55:40 +04:00
|
|
|
* Lookup an interface by name and return its opal_list index.
|
2004-01-14 21:24:30 +03:00
|
|
|
*
|
|
|
|
* @param if_name (IN) Interface name
|
2007-04-25 05:55:40 +04:00
|
|
|
* @return Interface opal_list index
|
2004-01-14 21:24:30 +03:00
|
|
|
*/
|
2006-08-20 19:54:04 +04:00
|
|
|
OPAL_DECLSPEC int opal_ifnametoindex(const char* if_name);
|
2004-01-14 21:24:30 +03:00
|
|
|
|
2007-04-25 05:55:40 +04:00
|
|
|
/**
|
|
|
|
* Lookup an interface by name and return its kernel index.
|
|
|
|
*
|
|
|
|
* @param if_name (IN) Interface name
|
|
|
|
* @return Interface kernel index
|
|
|
|
*/
|
2009-04-02 22:35:09 +04:00
|
|
|
OPAL_DECLSPEC int16_t opal_ifnametokindex(const char* if_name);
|
2007-04-25 05:55:40 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup an interface by opal_list index and return its kernel index.
|
|
|
|
*
|
|
|
|
* @param if_name (IN) Interface opal_list index
|
|
|
|
* @return Interface kernel index
|
|
|
|
*/
|
|
|
|
OPAL_DECLSPEC int opal_ifindextokindex(int if_index);
|
|
|
|
|
2004-01-14 21:24:30 +03:00
|
|
|
/**
|
|
|
|
* Returns the number of available interfaces.
|
|
|
|
*/
|
2006-08-20 19:54:04 +04:00
|
|
|
OPAL_DECLSPEC int opal_ifcount(void);
|
2004-01-14 21:24:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the index of the first available interface.
|
|
|
|
*/
|
2006-08-20 19:54:04 +04:00
|
|
|
OPAL_DECLSPEC int opal_ifbegin(void);
|
2004-01-14 21:24:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup the current position in the interface list by
|
|
|
|
* index and return the next available index (if it exists).
|
|
|
|
*
|
|
|
|
* @param if_index Returns the next available index from the
|
|
|
|
* current position.
|
|
|
|
*/
|
2006-08-20 19:54:04 +04:00
|
|
|
OPAL_DECLSPEC int opal_ifnext(int if_index);
|
2004-01-14 21:24:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup an interface by index and return its name.
|
|
|
|
*
|
|
|
|
* @param if_index (IN) Interface index
|
|
|
|
* @param if_name (OUT) Interface name buffer
|
|
|
|
* @param size (IN) Interface name buffer size
|
|
|
|
*/
|
2006-08-20 19:54:04 +04:00
|
|
|
OPAL_DECLSPEC int opal_ifindextoname(int if_index, char* if_name, int);
|
2004-01-14 21:24:30 +03:00
|
|
|
|
|
|
|
/**
|
2007-04-25 05:55:40 +04:00
|
|
|
* Lookup an interface by kernel index and return its name.
|
|
|
|
*
|
|
|
|
* @param if_index (IN) Interface kernel index
|
|
|
|
* @param if_name (OUT) Interface name buffer
|
|
|
|
* @param size (IN) Interface name buffer size
|
|
|
|
*/
|
|
|
|
OPAL_DECLSPEC int opal_ifkindextoname(int if_kindex, char* if_name, int);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup an interface by index and return its primary address.
|
2004-01-14 21:24:30 +03:00
|
|
|
*
|
|
|
|
* @param if_index (IN) Interface index
|
|
|
|
* @param if_name (OUT) Interface address buffer
|
|
|
|
* @param size (IN) Interface address buffer size
|
|
|
|
*/
|
2007-05-17 05:17:59 +04:00
|
|
|
OPAL_DECLSPEC int opal_ifindextoaddr(int if_index, struct sockaddr*,
|
2007-04-25 05:55:40 +04:00
|
|
|
unsigned int);
|
2004-01-14 21:24:30 +03:00
|
|
|
|
2004-01-26 21:41:37 +03:00
|
|
|
/**
|
2008-11-15 01:59:41 +03:00
|
|
|
* Lookup an interface by index and return its network mask (in CIDR
|
|
|
|
* notation -- NOT the actual netmask itself!).
|
2004-01-26 21:41:37 +03:00
|
|
|
*
|
|
|
|
* @param if_index (IN) Interface index
|
|
|
|
* @param if_name (OUT) Interface address buffer
|
|
|
|
* @param size (IN) Interface address buffer size
|
|
|
|
*/
|
2007-04-25 05:55:40 +04:00
|
|
|
OPAL_DECLSPEC int opal_ifindextomask(int if_index, uint32_t*, int);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup an interface by index and return its flags.
|
|
|
|
*
|
|
|
|
* @param if_index (IN) Interface index
|
|
|
|
* @param if_flags (OUT) Interface flags
|
|
|
|
*/
|
|
|
|
OPAL_DECLSPEC int opal_ifindextoflags(int if_index, uint32_t*);
|
2004-10-31 22:01:53 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if given hostname / IP address is a local address
|
|
|
|
*
|
|
|
|
* @param hostname (IN) Hostname (or stringified IP address)
|
|
|
|
* @return true if \c hostname is local, false otherwise
|
|
|
|
*/
|
2007-07-22 23:19:01 +04:00
|
|
|
OPAL_DECLSPEC bool opal_ifislocal(const char *hostname);
|
2004-10-31 22:01:53 +03:00
|
|
|
|
2009-10-09 19:24:41 +04:00
|
|
|
/**
|
|
|
|
* Convert a dot-delimited network tuple to an IP address
|
|
|
|
*
|
|
|
|
* @param addr (IN) character string tuple
|
|
|
|
* @param net (IN) Pointer to returned network address
|
|
|
|
* @param mask (IN) Pointer to returned netmask
|
|
|
|
* @return OPAL_SUCCESS if no problems encountered
|
|
|
|
* @return OPAL_ERROR if data could not be released
|
|
|
|
*/
|
2011-05-04 01:59:51 +04:00
|
|
|
OPAL_DECLSPEC int opal_iftupletoaddr(const char *addr, uint32_t *net, uint32_t *mask);
|
2009-10-09 19:24:41 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if given interface is loopback
|
|
|
|
*
|
|
|
|
* @param if_index (IN) Interface index
|
|
|
|
*/
|
|
|
|
OPAL_DECLSPEC bool opal_ifisloopback(int if_index);
|
|
|
|
|
2011-06-05 23:16:42 +04:00
|
|
|
/*
|
|
|
|
* Determine if a specified interface is included in a NULL-terminated argv array
|
|
|
|
*/
|
2011-06-07 06:09:11 +04:00
|
|
|
OPAL_DECLSPEC int opal_ifmatches(int idx, char **nets);
|
2009-10-09 19:24:41 +04:00
|
|
|
|
2007-04-25 23:08:07 +04:00
|
|
|
END_C_DECLS
|
2004-01-26 21:41:37 +03:00
|
|
|
|
2004-01-14 21:24:30 +03:00
|
|
|
#endif
|
|
|
|
|