blob: d6a5662b5200195553311d2aa09c696332631da8 [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
Neels Hofmeyr87e45502017-06-20 00:17:59 +02008 * Osmocom socket convenience functions
Harald Weltebd598e32011-08-16 23:26:52 +02009 */
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 Weltedda70fc2017-04-08 20:52:33 +020027int osmo_sock_init2(uint16_t family, uint16_t type, uint8_t proto,
28 const char *local_host, uint16_t local_port,
29 const char *remote_host, uint16_t remote_port, unsigned int flags);
30
Harald Welte68b15742011-05-22 21:47:29 +020031int osmo_sock_init_ofd(struct osmo_fd *ofd, int family, int type, int proto,
Pablo Neira Ayuso0849c9a2011-06-09 15:04:30 +020032 const char *host, uint16_t port, unsigned int flags);
Harald Welte68b15742011-05-22 21:47:29 +020033
Pau Espin Pedrol75989e62017-05-26 12:39:53 +020034int osmo_sock_init2_ofd(struct osmo_fd *ofd, int family, int type, int proto,
35 const char *local_host, uint16_t local_port,
36 const char *remote_host, uint16_t remote_port, unsigned int flags);
37
Harald Welte33cb71a2011-05-21 18:54:32 +020038int osmo_sock_init_sa(struct sockaddr *ss, uint16_t type,
Pablo Neira Ayuso0849c9a2011-06-09 15:04:30 +020039 uint8_t proto, unsigned int flags);
Harald Welte33cb71a2011-05-21 18:54:32 +020040
Harald Weltee4764422011-05-22 12:25:57 +020041int osmo_sockaddr_is_local(struct sockaddr *addr, unsigned int addrlen);
Harald Welte33cb71a2011-05-21 18:54:32 +020042
Álvaro Neira Ayuso5ade61a2014-03-24 13:02:00 +010043int osmo_sock_unix_init(uint16_t type, uint8_t proto,
44 const char *socket_path, unsigned int flags);
45
46int osmo_sock_unix_init_ofd(struct osmo_fd *ofd, uint16_t type, uint8_t proto,
47 const char *socket_path, unsigned int flags);
48
Harald Welte48f55832017-01-26 00:03:10 +010049char *osmo_sock_get_name(void *ctx, int fd);
50
Sylvain Munautdca7d2c2012-04-18 21:53:23 +020051/*! @} */