aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src
diff options
context:
space:
mode:
Diffstat (limited to 'openbsc/src')
-rw-r--r--openbsc/src/gprs/gtphub.c146
-rw-r--r--openbsc/src/gprs/gtphub_ares.c1
2 files changed, 3 insertions, 144 deletions
diff --git a/openbsc/src/gprs/gtphub.c b/openbsc/src/gprs/gtphub.c
index 58300ea13..b04469edb 100644
--- a/openbsc/src/gprs/gtphub.c
+++ b/openbsc/src/gprs/gtphub.c
@@ -25,9 +25,10 @@
#include <time.h>
#include <limits.h>
#include <unistd.h>
-#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <netdb.h>
#include <gtp.h>
#include <gtpie.h>
@@ -2786,146 +2787,3 @@ static int gtphub_resolve_ggsn(struct gtphub *hub,
}
-/* TODO move to osmocom/core/socket.c ? */
-/* use this in osmo_sock_init() to remove dup. */
-/* Internal: call getaddrinfo for osmo_sockaddr_init(). The caller is required
- to call freeaddrinfo(*result), iff zero is returned. */
-static int _osmo_getaddrinfo(struct addrinfo **result,
- uint16_t family, uint16_t type, uint8_t proto,
- const char *host, uint16_t port)
-{
- struct addrinfo hints;
- char portbuf[16];
-
- sprintf(portbuf, "%u", port);
- memset(&hints, '\0', sizeof(struct addrinfo));
- hints.ai_family = family;
- if (type == SOCK_RAW) {
- /* Workaround for glibc, that returns EAI_SERVICE (-8) if
- * SOCK_RAW and IPPROTO_GRE is used.
- */
- hints.ai_socktype = SOCK_DGRAM;
- hints.ai_protocol = IPPROTO_UDP;
- } else {
- hints.ai_socktype = type;
- hints.ai_protocol = proto;
- }
-
- return getaddrinfo(host, portbuf, &hints, result);
-}
-
-/* TODO move to osmocom/core/socket.c ? */
-int osmo_sockaddr_init(struct osmo_sockaddr *addr,
- uint16_t family, uint16_t type, uint8_t proto,
- const char *host, uint16_t port)
-{
- struct addrinfo *res;
- int rc;
- rc = _osmo_getaddrinfo(&res, family, type, proto, host, port);
-
- if (rc != 0) {
- LOG(LOGL_ERROR, "getaddrinfo returned error %d\n", (int)rc);
- return -EINVAL;
- }
-
- OSMO_ASSERT(res->ai_addrlen <= sizeof(addr->a));
- memcpy(&addr->a, res->ai_addr, res->ai_addrlen);
- addr->l = res->ai_addrlen;
- freeaddrinfo(res);
-
- return 0;
-}
-
-int osmo_sockaddr_to_strs(char *addr_str, size_t addr_str_len,
- char *port_str, size_t port_str_len,
- const struct osmo_sockaddr *addr,
- int flags)
-{
- int rc;
-
- if ((addr->l < 1) || (addr->l > sizeof(addr->a))) {
- LOGP(DGTPHUB, LOGL_ERROR, "Invalid address size: %d\n", addr->l);
- return -1;
- }
-
- if (addr->l > sizeof(addr->a)) {
- LOGP(DGTPHUB, LOGL_ERROR, "Invalid address: too long: %d\n",
- addr->l);
- return -1;
- }
-
- rc = getnameinfo((struct sockaddr*)&addr->a, addr->l,
- addr_str, addr_str_len,
- port_str, port_str_len,
- flags);
-
- if (rc)
- LOGP(DGTPHUB, LOGL_ERROR, "Invalid address: %s: %s\n",
- gai_strerror(rc), osmo_hexdump((uint8_t*)&addr->a,
- addr->l));
-
- return rc;
-}
-
-const char *osmo_sockaddr_to_strb(const struct osmo_sockaddr *addr,
- char *buf, size_t buf_len)
-{
- const int portbuf_len = 6;
- OSMO_ASSERT(buf_len > portbuf_len);
- char *portbuf = buf + buf_len - portbuf_len;
- buf_len -= portbuf_len;
- if (osmo_sockaddr_to_strs(buf, buf_len,
- portbuf, portbuf_len,
- addr,
- NI_NUMERICHOST | NI_NUMERICSERV))
- return NULL;
-
- char *pos = buf + strnlen(buf, buf_len-1);
- size_t len = buf_len - (pos - buf);
-
- snprintf(pos, len, " port %s", portbuf);
- buf[buf_len-1] = '\0';
-
- return buf;
-}
-
-const char *osmo_sockaddr_to_str(const struct osmo_sockaddr *addr)
-{
- static char buf[256];
- const char *result = osmo_sockaddr_to_strb(addr, buf, sizeof(buf));
- if (! result)
- return "(invalid)";
- return result;
-}
-
-int osmo_sockaddr_cmp(const struct osmo_sockaddr *a,
- const struct osmo_sockaddr *b)
-{
- if (a == b)
- return 0;
- if (!a)
- return -1;
- if (!b)
- return 1;
- if (a->l != b->l) {
- /* Lengths are not the same, but determine the order. Will
- * anyone ever sort a list by osmo_sockaddr though...? */
- int cmp = memcmp(&a->a, &b->a, (a->l < b->l)? a->l : b->l);
- if (cmp == 0) {
- if (a->l < b->l)
- return -1;
- else
- return 1;
- }
- return cmp;
- }
- return memcmp(&a->a, &b->a, a->l);
-}
-
-void osmo_sockaddr_copy(struct osmo_sockaddr *dst,
- const struct osmo_sockaddr *src)
-{
- OSMO_ASSERT(src->l <= sizeof(dst->a));
- memcpy(&dst->a, &src->a, src->l);
- dst->l = src->l;
-}
diff --git a/openbsc/src/gprs/gtphub_ares.c b/openbsc/src/gprs/gtphub_ares.c
index 667013b8b..0793ed421 100644
--- a/openbsc/src/gprs/gtphub_ares.c
+++ b/openbsc/src/gprs/gtphub_ares.c
@@ -27,6 +27,7 @@
#include <string.h>
#include <unistd.h>
+#include <netdb.h>
#include <openbsc/gtphub.h>
#include <openbsc/debug.h>