Sylvain Munaut | 12ba778 | 2014-06-16 10:13:40 +0200 | [diff] [blame] | 1 | #pragma once |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 2 | |
Harald Welte | ba6988b | 2011-08-17 12:46:48 +0200 | [diff] [blame] | 3 | /*! \defgroup socket Socket convenience functions |
| 4 | * @{ |
| 5 | */ |
| 6 | |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 7 | /*! \file socket.h |
| 8 | * \brief Osmocom socket convenience functions |
| 9 | */ |
| 10 | |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 11 | #include <stdint.h> |
Harald Welte | e476442 | 2011-05-22 12:25:57 +0200 | [diff] [blame] | 12 | |
| 13 | struct sockaddr; |
Holger Hans Peter Freyther | 58d3153 | 2012-03-16 09:18:12 +0100 | [diff] [blame] | 14 | struct osmo_fd; |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 15 | |
Pablo Neira Ayuso | 0849c9a | 2011-06-09 15:04:30 +0200 | [diff] [blame] | 16 | /* flags for osmo_sock_init. */ |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 17 | /*! connect the socket to a remote peer */ |
Pablo Neira Ayuso | 0849c9a | 2011-06-09 15:04:30 +0200 | [diff] [blame] | 18 | #define OSMO_SOCK_F_CONNECT (1 << 0) |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 19 | /*! bind the socket to a local address/port */ |
Pablo Neira Ayuso | 0849c9a | 2011-06-09 15:04:30 +0200 | [diff] [blame] | 20 | #define OSMO_SOCK_F_BIND (1 << 1) |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 21 | /*! switch socket to non-blocking mode */ |
Pablo Neira Ayuso | 0849c9a | 2011-06-09 15:04:30 +0200 | [diff] [blame] | 22 | #define OSMO_SOCK_F_NONBLOCK (1 << 2) |
| 23 | |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 24 | int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto, |
Pablo Neira Ayuso | 0849c9a | 2011-06-09 15:04:30 +0200 | [diff] [blame] | 25 | const char *host, uint16_t port, unsigned int flags); |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 26 | |
Harald Welte | dda70fc | 2017-04-08 20:52:33 +0200 | [diff] [blame] | 27 | int 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 Welte | 68b1574 | 2011-05-22 21:47:29 +0200 | [diff] [blame] | 31 | int osmo_sock_init_ofd(struct osmo_fd *ofd, int family, int type, int proto, |
Pablo Neira Ayuso | 0849c9a | 2011-06-09 15:04:30 +0200 | [diff] [blame] | 32 | const char *host, uint16_t port, unsigned int flags); |
Harald Welte | 68b1574 | 2011-05-22 21:47:29 +0200 | [diff] [blame] | 33 | |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 34 | int osmo_sock_init_sa(struct sockaddr *ss, uint16_t type, |
Pablo Neira Ayuso | 0849c9a | 2011-06-09 15:04:30 +0200 | [diff] [blame] | 35 | uint8_t proto, unsigned int flags); |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 36 | |
Harald Welte | e476442 | 2011-05-22 12:25:57 +0200 | [diff] [blame] | 37 | int osmo_sockaddr_is_local(struct sockaddr *addr, unsigned int addrlen); |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 38 | |
Álvaro Neira Ayuso | 5ade61a | 2014-03-24 13:02:00 +0100 | [diff] [blame] | 39 | int osmo_sock_unix_init(uint16_t type, uint8_t proto, |
| 40 | const char *socket_path, unsigned int flags); |
| 41 | |
| 42 | int osmo_sock_unix_init_ofd(struct osmo_fd *ofd, uint16_t type, uint8_t proto, |
| 43 | const char *socket_path, unsigned int flags); |
| 44 | |
Harald Welte | 48f5583 | 2017-01-26 00:03:10 +0100 | [diff] [blame] | 45 | char *osmo_sock_get_name(void *ctx, int fd); |
| 46 | |
Sylvain Munaut | dca7d2c | 2012-04-18 21:53:23 +0200 | [diff] [blame] | 47 | /*! @} */ |