libosmocore 0.9.6-23.20170220git32ee5af8.fc42
Osmocom core library
|
Files | |
file | socket.h |
Osmocom socket convenience functions. | |
file | socket.c |
Osmocom socket convenience functions. | |
Macros | |
#define | OSMO_SOCK_F_CONNECT (1 << 0) |
#define | OSMO_SOCK_F_BIND (1 << 1) |
#define | OSMO_SOCK_F_NONBLOCK (1 << 2) |
Functions | |
int | osmo_sock_init (uint16_t family, uint16_t type, uint8_t proto, const char *host, uint16_t port, unsigned int flags) |
Initialize a socket (including bind/connect) | |
int | osmo_sock_init_ofd (struct osmo_fd *ofd, int family, int type, int proto, const char *host, uint16_t port, unsigned int flags) |
Initialize a socket and fill osmo_fd. | |
int | osmo_sock_init_sa (struct sockaddr *ss, uint16_t type, uint8_t proto, unsigned int flags) |
Initialize a socket and fill sockaddr. | |
int | osmo_sockaddr_is_local (struct sockaddr *addr, unsigned int addrlen) |
Determine if the given address is a local address. | |
int | osmo_sock_unix_init (uint16_t type, uint8_t proto, const char *socket_path, unsigned int flags) |
Initialize a unix domain socket (including bind/connect) | |
int | osmo_sock_unix_init_ofd (struct osmo_fd *ofd, uint16_t type, uint8_t proto, const char *socket_path, unsigned int flags) |
Initialize a unix domain socket and fill osmo_fd. | |
char * | osmo_sock_get_name (void *ctx, int fd) |
Get address/port information on soocket in dyn-alloc string. | |
static int | osmo_fd_init_ofd (struct osmo_fd *ofd, int sfd) |
fill osmo_fd for a give sfd | |
static int | sockaddr_equal (const struct sockaddr *a, const struct sockaddr *b, unsigned int len) |
#define OSMO_SOCK_F_BIND (1 << 1) |
bind the socket to a local address/port
Referenced by gsmtap_source_add_sink_fd(), osmo_sock_init(), and osmo_sock_unix_init().
#define OSMO_SOCK_F_CONNECT (1 << 0) |
connect the socket to a remote peer
Referenced by gsmtap_source_init_fd(), osmo_sock_init(), and osmo_sock_unix_init().
#define OSMO_SOCK_F_NONBLOCK (1 << 2) |
switch socket to non-blocking mode
Referenced by osmo_sock_init(), and osmo_sock_unix_init().
|
inlinestatic |
fill osmo_fd for a give sfd
[out] | ofd | file descriptor (will be filled in) |
[in] | sfd | socket file descriptor |
This function fills the ofd structure.
References BSC_FD_READ, osmo_fd::fd, osmo_fd_register(), and osmo_fd::when.
Referenced by osmo_sock_init_ofd(), and osmo_sock_unix_init_ofd().
char * osmo_sock_get_name | ( | void * | ctx, |
int | fd ) |
Get address/port information on soocket in dyn-alloc string.
[in] | ctx | talloc context from which to allocate string buffer |
[in] | fd | file descriptor of socket |
int osmo_sock_init | ( | uint16_t | family, |
uint16_t | type, | ||
uint8_t | proto, | ||
const char * | host, | ||
uint16_t | port, | ||
unsigned int | flags ) |
Initialize a socket (including bind/connect)
[in] | family | Address Family like AF_INET, AF_INET6, AF_UNSPEC |
[in] | type | Socket type like SOCK_DGRAM, SOCK_STREAM |
[in] | proto | Protocol like IPPROTO_TCP, IPPROTO_UDP |
[in] | host | remote host name or IP address in string form |
[in] | port | remote port number in host byte order |
[in] | flags | flags like OSMO_SOCK_F_CONNECT |
This function creates a new socket of the designated family, type and proto and optionally binds or connects it, depending on the value of flags parameter.
References DLGLOBAL, LOGL_ERROR, LOGP, OSMO_SOCK_F_BIND, OSMO_SOCK_F_CONNECT, and OSMO_SOCK_F_NONBLOCK.
Referenced by gsmtap_source_init_fd(), osmo_sock_init_ofd(), and osmo_sock_init_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 ) |
Initialize a socket and fill osmo_fd.
[out] | ofd | file descriptor (will be filled in) |
[in] | family | Address Family like AF_INET, AF_INET6, AF_UNSPEC |
[in] | type | Socket type like SOCK_DGRAM, SOCK_STREAM |
[in] | proto | Protocol like IPPROTO_TCP, IPPROTO_UDP |
[in] | host | remote host name or IP address in string form |
[in] | port | remote port number in host byte order |
[in] | flags | flags like OSMO_SOCK_F_CONNECT |
This function creates (and optionall binds/connects) a socket using osmo_sock_init, but also fills the ofd structure.
References osmo_fd_init_ofd(), and osmo_sock_init().
int osmo_sock_init_sa | ( | struct sockaddr * | ss, |
uint16_t | type, | ||
uint8_t | proto, | ||
unsigned int | flags ) |
Initialize a socket and fill sockaddr.
[out] | ss | socket address (will be filled in) |
[in] | type | Socket type like SOCK_DGRAM, SOCK_STREAM |
[in] | proto | Protocol like IPPROTO_TCP, IPPROTO_UDP |
[in] | flags | flags like OSMO_SOCK_F_CONNECT |
This function creates (and optionall binds/connects) a socket using osmo_sock_init, but also fills the ss structure.
References DLGLOBAL, LOGL_ERROR, LOGP, and osmo_sock_init().
Referenced by gsmtap_source_add_sink_fd().
int osmo_sock_unix_init | ( | uint16_t | type, |
uint8_t | proto, | ||
const char * | socket_path, | ||
unsigned int | flags ) |
Initialize a unix domain socket (including bind/connect)
[in] | type | Socket type like SOCK_DGRAM, SOCK_STREAM |
[in] | proto | Protocol like IPPROTO_TCP, IPPROTO_UDP |
[in] | socket_path | path to identify the socket |
[in] | flags | flags like OSMO_SOCK_F_CONNECT |
This function creates a new unix domain socket, type and proto and optionally binds or connects it, depending on the value of flags parameter.
References DLGLOBAL, LOGL_ERROR, LOGP, OSMO_SOCK_F_BIND, OSMO_SOCK_F_CONNECT, and OSMO_SOCK_F_NONBLOCK.
Referenced by osmo_sock_unix_init_ofd().
int osmo_sock_unix_init_ofd | ( | struct osmo_fd * | ofd, |
uint16_t | type, | ||
uint8_t | proto, | ||
const char * | socket_path, | ||
unsigned int | flags ) |
Initialize a unix domain socket and fill osmo_fd.
[out] | ofd | file descriptor (will be filled in) |
[in] | type | Socket type like SOCK_DGRAM, SOCK_STREAM |
[in] | proto | Protocol like IPPROTO_TCP, IPPROTO_UDP |
[in] | socket_path | path to identify the socket |
[in] | flags | flags like OSMO_SOCK_F_CONNECT |
This function creates (and optionall binds/connects) a socket using osmo_sock_unix_init, but also fills the ofd structure.
References osmo_fd_init_ofd(), and osmo_sock_unix_init().
int osmo_sockaddr_is_local | ( | struct sockaddr * | addr, |
unsigned int | addrlen ) |
Determine if the given address is a local address.
[in] | addr | Socket Address |
[in] | addrlen | Length of socket address in bytes |
References DLGLOBAL, LOGL_ERROR, and LOGP.
Referenced by gsmtap_source_add_sink_fd().