summaryrefslogtreecommitdiffstats
path: root/src/shared/libosmocore/src/socket.c
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2011-09-02 22:21:13 +0200
committerSylvain Munaut <tnt@246tNt.com>2011-09-02 22:21:13 +0200
commit176f72a2edad961773a832f5499c16cc8b318441 (patch)
tree921da4dfcf3bb704511a383bce7910e1675de9f5 /src/shared/libosmocore/src/socket.c
parentd7410b752fc36e811c500f10718f0b73f2aa60f5 (diff)
parentfe28dedd4c25b5f0f3df39d5e33ce3639574406c (diff)
Merge commit 'fe28dedd4c25b5f0f3df39d5e33ce3639574406c'
Diffstat (limited to 'src/shared/libosmocore/src/socket.c')
-rw-r--r--src/shared/libosmocore/src/socket.c49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/shared/libosmocore/src/socket.c b/src/shared/libosmocore/src/socket.c
index f1fcccd5..1a1d71dc 100644
--- a/src/shared/libosmocore/src/socket.c
+++ b/src/shared/libosmocore/src/socket.c
@@ -1,5 +1,13 @@
#include "../config.h"
+/*! \addtogroup socket
+ * @{
+ */
+
+/*! \file socket.c
+ * \brief Osmocom socket convenience functions
+ */
+
#ifdef HAVE_SYS_SOCKET_H
#include <osmocom/core/logging.h>
@@ -18,6 +26,18 @@
#include <netdb.h>
#include <ifaddrs.h>
+/*! \brief Initialize a socket (including bind/connect)
+ * \param[in] family Address Family like AF_INET, AF_INET6, AF_UNSPEC
+ * \param[in] type Socket type like SOCK_DGRAM, SOCK_STREAM
+ * \param[in] proto Protocol like IPPROTO_TCP, IPPROTO_UDP
+ * \param[in] host remote host name or IP address in string form
+ * \param[in] port remote port number in host byte order
+ * \param[in] flags flags like \ref OSMO_SOCK_F_CONNECT
+ *
+ * This function creates a new socket of the designated \a family, \a
+ * type and \a proto and optionally binds or connects it, depending on
+ * the value of \a flags parameter.
+ */
int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
const char *host, uint16_t port, unsigned int flags)
{
@@ -93,6 +113,18 @@ int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
return sfd;
}
+/*! \brief Initialize a socket and fill \ref osmo_fd
+ * \param[out] osmocom file descriptor (will be filled in)
+ * \param[in] family Address Family like AF_INET, AF_INET6, AF_UNSPEC
+ * \param[in] type Socket type like SOCK_DGRAM, SOCK_STREAM
+ * \param[in] proto Protocol like IPPROTO_TCP, IPPROTO_UDP
+ * \param[in] host remote host name or IP address in string form
+ * \param[in] port remote port number in host byte order
+ * \param[in] flags flags like \ref OSMO_SOCK_F_CONNECT
+ *
+ * This function creates (and optionall binds/connects) a socket using
+ * \ref osmo_sock_init, but also fills the \a ofd structure.
+ */
int osmo_sock_init_ofd(struct osmo_fd *ofd, int family, int type, int proto,
const char *host, uint16_t port, unsigned int flags)
{
@@ -114,6 +146,15 @@ int osmo_sock_init_ofd(struct osmo_fd *ofd, int family, int type, int proto,
return sfd;
}
+/*! \brief Initialize a socket and fill \ref sockaddr
+ * \param[out] ss socket address (will be filled in)
+ * \param[in] type Socket type like SOCK_DGRAM, SOCK_STREAM
+ * \param[in] proto Protocol like IPPROTO_TCP, IPPROTO_UDP
+ * \param[in] flags flags like \ref OSMO_SOCK_F_CONNECT
+ *
+ * This function creates (and optionall binds/connects) a socket using
+ * \ref osmo_sock_init, but also fills the \a ss structure.
+ */
int osmo_sock_init_sa(struct sockaddr *ss, uint16_t type,
uint8_t proto, unsigned int flags)
{
@@ -177,7 +218,11 @@ static int sockaddr_equal(const struct sockaddr *a,
return 0;
}
-/* determine if the given address is a local address */
+/*! \brief Determine if the given address is a local address
+ * \param[in] addr Socket Address
+ * \param[in] addrlen Length of socket address in bytes
+ * \returns 1 if address is local, 0 otherwise.
+ */
int osmo_sockaddr_is_local(struct sockaddr *addr, socklen_t addrlen)
{
struct ifaddrs *ifaddr, *ifa;
@@ -198,3 +243,5 @@ int osmo_sockaddr_is_local(struct sockaddr *addr, socklen_t addrlen)
}
#endif /* HAVE_SYS_SOCKET_H */
+
+/*! }@ */