From b2d727a10256ed133f0db7f6760bfef73f8b9f6e Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 28 Apr 2016 07:53:49 +0200 Subject: ipa_server_conn: Add remote (peer) address to struct This is better than every implementation calling getpeername() on its own. --- include/osmocom/abis/ipa.h | 3 +++ src/input/ipa.c | 8 ++++++++ 2 files changed, 11 insertions(+) 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); -- cgit v1.2.3-59-g8ed1b