2019-04-05 10:44:08 +02:00
|
|
|
/** Node type: socket
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
2020-01-20 17:17:00 +01:00
|
|
|
* @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC
|
2019-04-05 10:44:08 +02:00
|
|
|
* @license GNU General Public License (version 3)
|
|
|
|
*
|
|
|
|
* VILLASnode
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#include <villas/node/config.h>
|
|
|
|
|
|
|
|
#if defined(LIBNL3_ROUTE_FOUND) && defined(__linux__)
|
|
|
|
#define WITH_SOCKET_LAYER_ETH
|
|
|
|
|
|
|
|
#include <linux/if_packet.h>
|
2019-04-05 10:53:51 +02:00
|
|
|
#include <netinet/ether.h>
|
2019-04-05 10:44:08 +02:00
|
|
|
#endif /* LIBNL3_ROUTE_FOUND */
|
|
|
|
|
2019-06-23 16:13:23 +02:00
|
|
|
enum class SocketLayer {
|
|
|
|
ETH,
|
|
|
|
IP,
|
|
|
|
UDP,
|
|
|
|
UNIX
|
2019-04-05 10:44:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
union sockaddr_union {
|
|
|
|
struct sockaddr sa;
|
|
|
|
struct sockaddr_storage ss;
|
|
|
|
struct sockaddr_in sin;
|
|
|
|
struct sockaddr_in6 sin6;
|
|
|
|
struct sockaddr_un sun;
|
|
|
|
#ifdef WITH_SOCKET_LAYER_ETH
|
|
|
|
struct sockaddr_ll sll;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Generate printable socket address depending on the address family
|
|
|
|
*
|
|
|
|
* A IPv4 address is formatted as dotted decimals followed by the port/protocol number
|
|
|
|
* A link layer address is formatted in hexadecimals digits seperated by colons and the inferface name
|
|
|
|
*
|
|
|
|
* @param sa A pointer to the socket address.
|
|
|
|
* @return The buffer containing the textual representation of the address. The caller is responsible to free() this buffer!
|
|
|
|
*/
|
|
|
|
char * socket_print_addr(struct sockaddr *saddr);
|
|
|
|
|
|
|
|
/** Parse a socket address depending on the address family
|
|
|
|
*
|
|
|
|
* A IPv4 address has the follwing format: [hostname/ip]:[port/protocol]
|
|
|
|
* A link layer address has the following format: [mac]%[interface]:[ethertype]
|
|
|
|
*
|
|
|
|
* @todo Add support for autodetection of address type
|
|
|
|
*
|
|
|
|
* @param str A string specifiying the socket address. See description for allowed formats.
|
|
|
|
* @param sa A pointer to the resolved address
|
|
|
|
* @param layer Specifies the address type in which the addr is given
|
|
|
|
* @param flags Flags for getaddrinfo(2)
|
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
|
|
|
*/
|
2019-06-23 16:13:23 +02:00
|
|
|
int socket_parse_address(const char *str, struct sockaddr *sa, enum SocketLayer layer, int flags);
|
2019-04-05 10:44:08 +02:00
|
|
|
|
|
|
|
int socket_compare_addr(struct sockaddr *x, struct sockaddr *y);
|