libosmocore  1.0.1.85-9f28
Osmocom core library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
socket.h
Go to the documentation of this file.
1 
4 #pragma once
5 
10 #include <stdint.h>
11 #include <stdbool.h>
12 #include <stddef.h>
13 
14 #if (!EMBEDDED)
15 #include <arpa/inet.h>
16 
18 #define OSMO_SOCK_NAME_MAXLEN (2 + INET6_ADDRSTRLEN + 1 + 5 + 3 + 2 + INET6_ADDRSTRLEN + 1 + 5 + 1)
19 #endif
20 
21 struct sockaddr_in;
22 struct sockaddr;
23 struct osmo_fd;
24 
25 /* flags for osmo_sock_init. */
27 #define OSMO_SOCK_F_CONNECT (1 << 0)
28 
29 #define OSMO_SOCK_F_BIND (1 << 1)
30 
31 #define OSMO_SOCK_F_NONBLOCK (1 << 2)
32 
33 #define OSMO_SOCK_F_NO_MCAST_LOOP (1 << 3)
34 
35 #define OSMO_SOCK_F_NO_MCAST_ALL (1 << 4)
36 
37 #define OSMO_SOCK_F_UDP_REUSEADDR (1 << 5)
38 
39 int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
40  const char *host, uint16_t port, unsigned int flags);
41 
42 int osmo_sock_init2(uint16_t family, uint16_t type, uint8_t proto,
43  const char *local_host, uint16_t local_port,
44  const char *remote_host, uint16_t remote_port, unsigned int flags);
45 
46 int osmo_sock_init_ofd(struct osmo_fd *ofd, int family, int type, int proto,
47  const char *host, uint16_t port, unsigned int flags);
48 
49 int osmo_sock_init2_ofd(struct osmo_fd *ofd, int family, int type, int proto,
50  const char *local_host, uint16_t local_port,
51  const char *remote_host, uint16_t remote_port, unsigned int flags);
52 
53 int osmo_sock_init_sa(struct sockaddr *ss, uint16_t type,
54  uint8_t proto, unsigned int flags);
55 
56 int osmo_sockaddr_is_local(struct sockaddr *addr, unsigned int addrlen);
57 
58 unsigned int osmo_sockaddr_to_str_and_uint(char *addr, unsigned int addr_len, uint16_t *port,
59  const struct sockaddr *sa);
60 size_t osmo_sockaddr_in_to_str_and_uint(char *addr, unsigned int addr_len, uint16_t *port,
61  const struct sockaddr_in *sin);
62 
63 int osmo_sock_unix_init(uint16_t type, uint8_t proto,
64  const char *socket_path, unsigned int flags);
65 
66 int osmo_sock_unix_init_ofd(struct osmo_fd *ofd, uint16_t type, uint8_t proto,
67  const char *socket_path, unsigned int flags);
68 
69 char *osmo_sock_get_name(const void *ctx, int fd);
70 const char *osmo_sock_get_name2(int fd);
71 int osmo_sock_get_name_buf(char *str, size_t str_len, int fd);
72 int osmo_sock_get_ip_and_port(int fd, char *ip, size_t ip_len, char *port, size_t port_len, bool local);
73 int osmo_sock_get_local_ip(int fd, char *host, size_t len);
74 int osmo_sock_get_local_ip_port(int fd, char *port, size_t len);
75 int osmo_sock_get_remote_ip(int fd, char *host, size_t len);
76 int osmo_sock_get_remote_ip_port(int fd, char *port, size_t len);
77 
78 
79 int osmo_sock_mcast_loop_set(int fd, bool enable);
80 int osmo_sock_mcast_ttl_set(int fd, uint8_t ttl);
81 int osmo_sock_mcast_all_set(int fd, bool enable);
82 int osmo_sock_mcast_subscribe(int fd, const char *grp_addr);
83 
84 int osmo_sock_local_ip(char *local_ip, const char *remote_ip);
85 
int osmo_sock_get_local_ip_port(int fd, char *port, size_t len)
unsigned int osmo_sockaddr_to_str_and_uint(char *addr, unsigned int addr_len, uint16_t *port, const struct sockaddr *sa)
int osmo_sock_init_ofd(struct osmo_fd *ofd, int family, int type, int proto, const char *host, uint16_t port, unsigned int flags)
int osmo_sock_mcast_loop_set(int fd, bool enable)
int osmo_sock_get_name_buf(char *str, size_t str_len, int fd)
size_t osmo_sockaddr_in_to_str_and_uint(char *addr, unsigned int addr_len, uint16_t *port, const struct sockaddr_in *sin)
int osmo_sock_get_ip_and_port(int fd, char *ip, size_t ip_len, char *port, size_t port_len, bool local)
int osmo_sock_mcast_ttl_set(int fd, uint8_t ttl)
int osmo_sock_local_ip(char *local_ip, const char *remote_ip)
int osmo_sock_init2_ofd(struct osmo_fd *ofd, int family, int type, int proto, const char *local_host, uint16_t local_port, const char *remote_host, uint16_t remote_port, unsigned int flags)
int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto, const char *host, uint16_t port, unsigned int flags)
int osmo_sock_mcast_all_set(int fd, bool enable)
int osmo_sock_mcast_subscribe(int fd, const char *grp_addr)
int osmo_sock_init_sa(struct sockaddr *ss, uint16_t type, uint8_t proto, unsigned int flags)
int osmo_sockaddr_is_local(struct sockaddr *addr, unsigned int addrlen)
char * osmo_sock_get_name(const void *ctx, int fd)
int osmo_sock_init2(uint16_t family, uint16_t type, uint8_t proto, const char *local_host, uint16_t local_port, const char *remote_host, uint16_t remote_port, unsigned int flags)
int osmo_sock_get_remote_ip_port(int fd, char *port, size_t len)
uint8_t type
see GSMTAP_TYPE_*
Definition: gsmtap.h:115
static size_t len(const char *str)
int osmo_sock_get_local_ip(int fd, char *host, size_t len)
int osmo_sock_unix_init(uint16_t type, uint8_t proto, const char *socket_path, unsigned int flags)
int osmo_sock_get_remote_ip(int fd, char *host, size_t len)
Structure representing a file dsecriptor.
Definition: select.h:28
int osmo_sock_unix_init_ofd(struct osmo_fd *ofd, uint16_t type, uint8_t proto, const char *socket_path, unsigned int flags)
const char * osmo_sock_get_name2(int fd)
int fd
actual operating-system level file decriptor
Definition: select.h:32