2019-09-18 07:42:13 -04:00
|
|
|
/* Copyright (C) 2019 Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LIBIGLOO__SOCKETADDR_H_
|
|
|
|
#define _LIBIGLOO__SOCKETADDR_H_
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Put a good description of this file here
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Put stuff here */
|
|
|
|
|
2019-09-18 14:40:46 -04:00
|
|
|
/* About thread safety:
|
|
|
|
* This set of functions is not thread safe.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <igloo/config.h>
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
|
|
|
|
igloo_RO_FORWARD_TYPE(igloo_socketaddr_t);
|
|
|
|
|
2019-10-02 02:27:16 -04:00
|
|
|
/* Domain of sockets */
|
2019-09-18 14:40:46 -04:00
|
|
|
typedef enum {
|
2019-10-02 02:27:16 -04:00
|
|
|
/* Special value used for unspecified or not jet known domain. */
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_SOCKETADDR_DOMAIN_UNSPEC = 0,
|
2019-10-02 02:27:16 -04:00
|
|
|
/* Unix Domain Sockets, AKA AF_UNIX */
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_SOCKETADDR_DOMAIN_UNIX,
|
2019-10-02 02:27:16 -04:00
|
|
|
/* IPv4 Sockets, AKA AF_INET */
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_SOCKETADDR_DOMAIN_INET4,
|
2019-10-02 02:27:16 -04:00
|
|
|
/* IPv6 Sockets, AKA AF_INET6 */
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_SOCKETADDR_DOMAIN_INET6
|
|
|
|
} igloo_socketaddr_domain_t;
|
|
|
|
|
2019-10-02 02:27:16 -04:00
|
|
|
/* Socket type */
|
2019-09-18 14:40:46 -04:00
|
|
|
typedef enum {
|
2019-10-02 02:27:16 -04:00
|
|
|
/* Special value used for unspecified or not jet known type. */
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_SOCKETADDR_TYPE_UNSPEC = 0,
|
2019-10-02 02:27:16 -04:00
|
|
|
/* Stream sockets */
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_SOCKETADDR_TYPE_STREAM,
|
2019-10-02 02:27:16 -04:00
|
|
|
/* Datagram sockets */
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_SOCKETADDR_TYPE_DGRAM,
|
2019-10-02 02:27:16 -04:00
|
|
|
/* Sequenced and reliable datagram sockets */
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_SOCKETADDR_TYPE_SEQPACK,
|
2019-10-02 02:27:16 -04:00
|
|
|
/* Reliable datagram sockets */
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_SOCKETADDR_TYPE_RDM
|
|
|
|
} igloo_socketaddr_type_t;
|
|
|
|
|
2019-10-02 02:27:16 -04:00
|
|
|
/* Specific socket protocol */
|
2019-09-18 14:40:46 -04:00
|
|
|
typedef enum {
|
2019-10-02 02:27:16 -04:00
|
|
|
/* Special value used for unspecified or not jet known protocol. */
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_SOCKETADDR_PROTOCOL_UNSPEC = 0,
|
2019-10-02 02:27:16 -04:00
|
|
|
/* Transmission Control Protocol */
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_SOCKETADDR_PROTOCOL_TCP,
|
2019-10-02 02:27:16 -04:00
|
|
|
/* User Datagram Protocol */
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_SOCKETADDR_PROTOCOL_UDP,
|
2019-10-02 02:27:16 -04:00
|
|
|
/* Datagram Congestion Control Protocol */
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_SOCKETADDR_PROTOCOL_DCCP,
|
2019-10-02 02:27:16 -04:00
|
|
|
/* Stream Control Transmission Protocol */
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_SOCKETADDR_PROTOCOL_SCTP,
|
2019-10-02 02:27:16 -04:00
|
|
|
/* Lightweight User Datagram Protocol */
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_SOCKETADDR_PROTOCOL_UDPLITE
|
|
|
|
} igloo_socketaddr_protocol_t;
|
|
|
|
|
2019-10-03 04:41:28 -04:00
|
|
|
/* This set of functions convert Domain, Type, and Protocol representations between enum and string values.
|
|
|
|
*
|
|
|
|
* Those functions are very helpful for parsing and writing config files, and for debug and log output.
|
|
|
|
*/
|
|
|
|
igloo_error_t igloo_socketaddr_domain2str(const char **str, igloo_socketaddr_domain_t domain);
|
|
|
|
igloo_error_t igloo_socketaddr_str2domain(igloo_socketaddr_domain_t *domain, const char *str);
|
|
|
|
igloo_error_t igloo_socketaddr_type2str(const char **str, igloo_socketaddr_type_t type);
|
|
|
|
igloo_error_t igloo_socketaddr_str2type(igloo_socketaddr_type_t *type, const char *str);
|
|
|
|
igloo_error_t igloo_socketaddr_protocol2str(const char **str, igloo_socketaddr_protocol_t protocol);
|
|
|
|
igloo_error_t igloo_socketaddr_str2protocol(igloo_socketaddr_protocol_t *protocol, const char *str);
|
|
|
|
|
2019-10-02 02:27:16 -04:00
|
|
|
/* This creates a new address object.
|
|
|
|
* Parameters:
|
|
|
|
* name, associated, instance
|
|
|
|
* See igloo_ro_new().
|
|
|
|
* domain, type, protocol
|
|
|
|
* Domain, Type, and Protocol for the new address. Can be igloo_SOCKETADDR_*_UNSPEC.
|
|
|
|
*/
|
2019-09-25 03:00:11 -04:00
|
|
|
igloo_socketaddr_t * igloo_socketaddr_new(igloo_socketaddr_domain_t domain, igloo_socketaddr_type_t type, igloo_socketaddr_protocol_t protocol, const char *name, igloo_ro_t associated, igloo_ro_t instance, igloo_error_t *error);
|
2019-10-03 04:16:16 -04:00
|
|
|
|
|
|
|
/* Gets base information on the address.
|
|
|
|
* Parameters:
|
|
|
|
* addr
|
|
|
|
* The address to operate on.
|
|
|
|
* domain, type, protocol
|
|
|
|
* The address' Domain, Type, and Protocol.
|
|
|
|
*/
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_error_t igloo_socketaddr_get_base(igloo_socketaddr_t *addr, igloo_socketaddr_domain_t *domain, igloo_socketaddr_type_t *type, igloo_socketaddr_protocol_t *protocol);
|
|
|
|
|
2019-10-03 04:16:16 -04:00
|
|
|
/* Get or set the address' node value.
|
|
|
|
*
|
|
|
|
* The Node is a protocol dependent representation of a node on the network.
|
|
|
|
* This might be a nodename or hostname, an IP address, a MAC address or anything else
|
|
|
|
* that identifies the node.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* addr
|
|
|
|
* The address to operate on.
|
|
|
|
* node
|
|
|
|
* The node value to set or get.
|
|
|
|
*/
|
|
|
|
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_error_t igloo_socketaddr_set_node(igloo_socketaddr_t *addr, const char *node);
|
|
|
|
igloo_error_t igloo_socketaddr_get_node(igloo_socketaddr_t *addr, const char **node);
|
2019-10-03 04:16:16 -04:00
|
|
|
/* Get the IP address of the address
|
|
|
|
*
|
|
|
|
* This gets the currently used IP address for the address if any.
|
|
|
|
* The IP address can not be set directly. Use igloo_socketaddr_set_node() to set the node.
|
|
|
|
*
|
|
|
|
* See also igloo_socketaddr_set_node().
|
|
|
|
*
|
|
|
|
* addr
|
|
|
|
* The address to operate on.
|
|
|
|
* ip
|
|
|
|
* The ip address used in the address.
|
|
|
|
*/
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_error_t igloo_socketaddr_get_ip (igloo_socketaddr_t *addr, const char **ip);
|
2019-10-03 04:16:16 -04:00
|
|
|
|
|
|
|
/* Get or set the addresse' port number.
|
|
|
|
*
|
|
|
|
* This sets or get the port number for addresses of domains that use ports.
|
|
|
|
*
|
|
|
|
* See also igloo_socketaddr_set_service().
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* addr
|
|
|
|
* The address to operate on.
|
|
|
|
* port
|
|
|
|
* The port value to set or get.
|
|
|
|
*/
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_error_t igloo_socketaddr_set_port(igloo_socketaddr_t *addr, uint16_t port);
|
|
|
|
igloo_error_t igloo_socketaddr_get_port(igloo_socketaddr_t *addr, uint16_t *port);
|
2019-10-03 04:16:16 -04:00
|
|
|
|
|
|
|
/* Set the service to use for the address.
|
|
|
|
*
|
|
|
|
* For port based domains this takes the port name or number as a string.
|
|
|
|
* This is very useful for parsing user input.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* addr
|
|
|
|
* The address to operate on.
|
|
|
|
* service
|
|
|
|
* The service to set.
|
|
|
|
*/
|
2019-09-18 21:07:39 -04:00
|
|
|
igloo_error_t igloo_socketaddr_set_service(igloo_socketaddr_t *addr, const char *service);
|
2019-10-03 04:16:16 -04:00
|
|
|
|
|
|
|
/* Get or set the addresse' path.
|
|
|
|
*
|
|
|
|
* This sets or get the path for addresses of domains that use paths.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* addr
|
|
|
|
* The address to operate on.
|
|
|
|
* path
|
|
|
|
* The path value to set or get.
|
|
|
|
*/
|
2019-09-18 14:40:46 -04:00
|
|
|
igloo_error_t igloo_socketaddr_set_path(igloo_socketaddr_t *addr, const char *path);
|
|
|
|
igloo_error_t igloo_socketaddr_get_path(igloo_socketaddr_t *addr, const char **path);
|
|
|
|
|
2019-09-18 07:42:13 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* ! _LIBIGLOO__SOCKETADDR_H_ */
|