summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2016-04-28 07:53:49 +0200
committerHarald Welte <laforge@gnumonks.org>2016-04-29 12:59:27 +0200
commitb2d727a10256ed133f0db7f6760bfef73f8b9f6e (patch)
tree5f9d7585a5e827c4e74c99665f8fb1f9de0bbdcd
parentSet connected mode after setting remote address (diff)
downloadlibosmo-abis-b2d727a10256ed133f0db7f6760bfef73f8b9f6e.tar.xz
libosmo-abis-b2d727a10256ed133f0db7f6760bfef73f8b9f6e.zip
ipa_server_conn: Add remote (peer) address to struct
This is better than every implementation calling getpeername() on its own.
-rw-r--r--include/osmocom/abis/ipa.h3
-rw-r--r--src/input/ipa.c8
2 files changed, 11 insertions, 0 deletions
diff --git a/include/osmocom/abis/ipa.h b/include/osmocom/abis/ipa.h
index 6e9f9dd..6447ccd 100644
--- a/include/osmocom/abis/ipa.h
+++ b/include/osmocom/abis/ipa.h
@@ -38,6 +38,9 @@ struct ipa_server_conn {
int (*cb)(struct ipa_server_conn *peer, struct msgb *msg);
void *data;
struct msgb *pending_msg;
+ /* remote address information */
+ const char *addr;
+ uint16_t port;
};
struct ipa_server_conn *
diff --git a/src/input/ipa.c b/src/input/ipa.c
index a10a418..bd1671b 100644
--- a/src/input/ipa.c
+++ b/src/input/ipa.c
@@ -401,6 +401,8 @@ ipa_server_conn_create(void *ctx, struct ipa_server_link *link, int fd,
int (*closed_cb)(struct ipa_server_conn *conn), void *data)
{
struct ipa_server_conn *conn;
+ struct sockaddr_in sa;
+ socklen_t sa_len = sizeof(sa);
conn = talloc_zero(ctx, struct ipa_server_conn);
if (conn == NULL) {
@@ -418,6 +420,12 @@ ipa_server_conn_create(void *ctx, struct ipa_server_link *link, int fd,
conn->data = data;
INIT_LLIST_HEAD(&conn->tx_queue);
+ if (!getpeername(fd, (struct sockaddr *)&sa, &sa_len)) {
+ char *str = inet_ntoa(sa.sin_addr);
+ conn->addr = talloc_strdup(conn, str);
+ conn->port = ntohs(sa.sin_port);
+ }
+
if (osmo_fd_register(&conn->ofd) < 0) {
LOGP(DLINP, LOGL_ERROR, "could not register FD\n");
talloc_free(conn);