blob: 6ef0912e5fa12da2e95531e06e1480e887d38335 [file] [log] [blame]
Sylvain Munaut12ba7782014-06-16 10:13:40 +02001#pragma once
Harald Welte33cb71a2011-05-21 18:54:32 +02002
Harald Welteba6988b2011-08-17 12:46:48 +02003/*! \defgroup socket Socket convenience functions
4 * @{
5 */
6
Harald Weltebd598e32011-08-16 23:26:52 +02007/*! \file socket.h
8 * \brief Osmocom socket convenience functions
9 */
10
Harald Welte33cb71a2011-05-21 18:54:32 +020011#include <stdint.h>
Harald Weltee4764422011-05-22 12:25:57 +020012
13struct sockaddr;
Holger Hans Peter Freyther58d31532012-03-16 09:18:12 +010014struct osmo_fd;
Harald Welte33cb71a2011-05-21 18:54:32 +020015
Pablo Neira Ayuso0849c9a2011-06-09 15:04:30 +020016/* flags for osmo_sock_init. */
Harald Welte2d2e2cc2016-04-25 12:11:20 +020017/*! connect the socket to a remote peer */
Pablo Neira Ayuso0849c9a2011-06-09 15:04:30 +020018#define OSMO_SOCK_F_CONNECT (1 << 0)
Harald Welte2d2e2cc2016-04-25 12:11:20 +020019/*! bind the socket to a local address/port */
Pablo Neira Ayuso0849c9a2011-06-09 15:04:30 +020020#define OSMO_SOCK_F_BIND (1 << 1)
Harald Welte2d2e2cc2016-04-25 12:11:20 +020021/*! switch socket to non-blocking mode */
Pablo Neira Ayuso0849c9a2011-06-09 15:04:30 +020022#define OSMO_SOCK_F_NONBLOCK (1 << 2)
23
Harald Welte33cb71a2011-05-21 18:54:32 +020024int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
Pablo Neira Ayuso0849c9a2011-06-09 15:04:30 +020025 const char *host, uint16_t port, unsigned int flags);
Harald Welte33cb71a2011-05-21 18:54:32 +020026
Harald Welte68b15742011-05-22 21:47:29 +020027int osmo_sock_init_ofd(struct osmo_fd *ofd, int family, int type, int proto,
Pablo Neira Ayuso0849c9a2011-06-09 15:04:30 +020028 const char *host, uint16_t port, unsigned int flags);
Harald Welte68b15742011-05-22 21:47:29 +020029
Harald Welte33cb71a2011-05-21 18:54:32 +020030int osmo_sock_init_sa(struct sockaddr *ss, uint16_t type,
Pablo Neira Ayuso0849c9a2011-06-09 15:04:30 +020031 uint8_t proto, unsigned int flags);
Harald Welte33cb71a2011-05-21 18:54:32 +020032
Harald Weltee4764422011-05-22 12:25:57 +020033int osmo_sockaddr_is_local(struct sockaddr *addr, unsigned int addrlen);
Harald Welte33cb71a2011-05-21 18:54:32 +020034
Álvaro Neira Ayuso5ade61a2014-03-24 13:02:00 +010035int osmo_sock_unix_init(uint16_t type, uint8_t proto,
36 const char *socket_path, unsigned int flags);
37
38int osmo_sock_unix_init_ofd(struct osmo_fd *ofd, uint16_t type, uint8_t proto,
39 const char *socket_path, unsigned int flags);
40
Sylvain Munautdca7d2c2012-04-18 21:53:23 +020041/*! @} */