Change in libosmocore[master]: add osmo_sockaddr_local_ip() to determine the local address for a rem...
lynxis lazus has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/19416 ) Change subject: add osmo_sockaddr_local_ip() to determine the local address for a remote. .. add osmo_sockaddr_local_ip() to determine the local address for a remote. Similiar to osmo_sock_local_ip but for osmo_sockaddr. Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 --- M include/osmocom/core/socket.h M src/socket.c 2 files changed, 25 insertions(+), 0 deletions(-) Approvals: Jenkins Builder: Verified pespin: Looks good to me, approved diff --git a/include/osmocom/core/socket.h b/include/osmocom/core/socket.h index e417f42..47a372c 100644 --- a/include/osmocom/core/socket.h +++ b/include/osmocom/core/socket.h @@ -113,6 +113,8 @@ int osmo_sock_local_ip(char *local_ip, const char *remote_ip); +int osmo_sockaddr_local_ip(struct osmo_sockaddr *local_ip, + const struct osmo_sockaddr *remote_ip); int osmo_sockaddr_cmp(struct osmo_sockaddr *a, struct osmo_sockaddr *b); #endif /* (!EMBEDDED) */ diff --git a/src/socket.c b/src/socket.c index 803af31..f078242 100644 --- a/src/socket.c +++ b/src/socket.c @@ -1662,6 +1662,29 @@ return 0; } +/*! Determine the matching local address for a given remote address. + * \param[out] local_ip caller provided memory for resulting local address + * \param[in] remote_ip remote address + * \returns 0 on success; negative otherwise + */ +int osmo_sockaddr_local_ip(struct osmo_sockaddr *local_ip, const struct osmo_sockaddr *remote_ip) +{ + int sfd; + int rc; + socklen_t local_ip_len; + + sfd = osmo_sock_init_osa(SOCK_DGRAM, IPPROTO_UDP, NULL, remote_ip, OSMO_SOCK_F_CONNECT); + if (sfd < 0) + return -EINVAL; + + memset(local_ip, 0, sizeof(*local_ip)); + local_ip_len = sizeof(*local_ip); + rc = getsockname(sfd, (struct sockaddr *)local_ip, _ip_len); + close(sfd); + + return rc; +} + /*! Compare two osmo_sockaddr. * \param[in] a * \param[in] b -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19416 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 Gerrit-Change-Number: 19416 Gerrit-PatchSet: 20 Gerrit-Owner: lynxis lazus Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel Gerrit-Reviewer: laforge Gerrit-Reviewer: lynxis lazus Gerrit-Reviewer: pespin Gerrit-MessageType: merged
Change in libosmocore[master]: add osmo_sockaddr_local_ip() to determine the local address for a rem...
pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/19416 ) Change subject: add osmo_sockaddr_local_ip() to determine the local address for a remote. .. Patch Set 20: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19416 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 Gerrit-Change-Number: 19416 Gerrit-PatchSet: 20 Gerrit-Owner: lynxis lazus Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel Gerrit-Reviewer: laforge Gerrit-Reviewer: lynxis lazus Gerrit-Reviewer: pespin Gerrit-Comment-Date: Mon, 07 Sep 2020 14:31:04 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
Change in libosmocore[master]: add osmo_sockaddr_local_ip() to determine the local address for a rem...
lynxis lazus has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/19416 ) Change subject: add osmo_sockaddr_local_ip() to determine the local address for a remote. .. Patch Set 20: (1 comment) https://gerrit.osmocom.org/c/libosmocore/+/19416/19/src/socket.c File src/socket.c: https://gerrit.osmocom.org/c/libosmocore/+/19416/19/src/socket.c@1684 PS19, Line 1684:if (rc < 0) > Ack Done -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19416 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 Gerrit-Change-Number: 19416 Gerrit-PatchSet: 20 Gerrit-Owner: lynxis lazus Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel Gerrit-Reviewer: laforge Gerrit-Reviewer: lynxis lazus Gerrit-Reviewer: pespin Gerrit-Comment-Date: Mon, 07 Sep 2020 14:22:46 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: pespin Comment-In-Reply-To: laforge Gerrit-MessageType: comment
Change in libosmocore[master]: add osmo_sockaddr_local_ip() to determine the local address for a rem...
Hello pespin, daniel, laforge, Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/libosmocore/+/19416 to look at the new patch set (#20). Change subject: add osmo_sockaddr_local_ip() to determine the local address for a remote. .. add osmo_sockaddr_local_ip() to determine the local address for a remote. Similiar to osmo_sock_local_ip but for osmo_sockaddr. Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 --- M include/osmocom/core/socket.h M src/socket.c 2 files changed, 25 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/16/19416/20 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19416 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 Gerrit-Change-Number: 19416 Gerrit-PatchSet: 20 Gerrit-Owner: lynxis lazus Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel Gerrit-Reviewer: laforge Gerrit-Reviewer: lynxis lazus Gerrit-Reviewer: pespin Gerrit-MessageType: newpatchset
Change in libosmocore[master]: add osmo_sockaddr_local_ip() to determine the local address for a rem...
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/19416 ) Change subject: add osmo_sockaddr_local_ip() to determine the local address for a remote. .. Patch Set 19: (1 comment) https://gerrit.osmocom.org/c/libosmocore/+/19416/19/src/socket.c File src/socket.c: https://gerrit.osmocom.org/c/libosmocore/+/19416/19/src/socket.c@1684 PS19, Line 1684:if (rc < 0) > Simply return rc; here? Ack -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19416 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 Gerrit-Change-Number: 19416 Gerrit-PatchSet: 19 Gerrit-Owner: lynxis lazus Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel Gerrit-Reviewer: laforge Gerrit-Reviewer: lynxis lazus Gerrit-Reviewer: pespin Gerrit-Comment-Date: Mon, 07 Sep 2020 08:04:37 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: pespin Gerrit-MessageType: comment
Change in libosmocore[master]: add osmo_sockaddr_local_ip() to determine the local address for a rem...
pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/19416 ) Change subject: add osmo_sockaddr_local_ip() to determine the local address for a remote. .. Patch Set 19: Code-Review+2 (1 comment) https://gerrit.osmocom.org/c/libosmocore/+/19416/19/src/socket.c File src/socket.c: https://gerrit.osmocom.org/c/libosmocore/+/19416/19/src/socket.c@1684 PS19, Line 1684:if (rc < 0) Simply return rc; here? -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19416 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 Gerrit-Change-Number: 19416 Gerrit-PatchSet: 19 Gerrit-Owner: lynxis lazus Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel Gerrit-Reviewer: laforge Gerrit-Reviewer: lynxis lazus Gerrit-Reviewer: pespin Gerrit-Comment-Date: Fri, 04 Sep 2020 11:38:33 + Gerrit-HasComments: Yes Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
Change in libosmocore[master]: add osmo_sockaddr_local_ip() to determine the local address for a rem...
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/19416 ) Change subject: add osmo_sockaddr_local_ip() to determine the local address for a remote. .. Patch Set 19: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19416 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 Gerrit-Change-Number: 19416 Gerrit-PatchSet: 19 Gerrit-Owner: lynxis lazus Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel Gerrit-Reviewer: laforge Gerrit-Reviewer: lynxis lazus Gerrit-Reviewer: pespin Gerrit-Comment-Date: Fri, 04 Sep 2020 07:38:51 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
Change in libosmocore[master]: add osmo_sockaddr_local_ip() to determine the local address for a rem...
daniel has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/19416 ) Change subject: add osmo_sockaddr_local_ip() to determine the local address for a remote. .. Patch Set 19: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19416 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 Gerrit-Change-Number: 19416 Gerrit-PatchSet: 19 Gerrit-Owner: lynxis lazus Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel Gerrit-Reviewer: laforge Gerrit-Reviewer: lynxis lazus Gerrit-Reviewer: pespin Gerrit-Comment-Date: Wed, 02 Sep 2020 17:03:19 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
Change in libosmocore[master]: add osmo_sockaddr_local_ip() to determine the local address for a rem...
Hello pespin, laforge, Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/libosmocore/+/19416 to look at the new patch set (#17). Change subject: add osmo_sockaddr_local_ip() to determine the local address for a remote. .. add osmo_sockaddr_local_ip() to determine the local address for a remote. Similiar to osmo_sock_local_ip but for osmo_sockaddr. Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 --- M include/osmocom/core/socket.h M src/socket.c 2 files changed, 27 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/16/19416/17 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19416 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 Gerrit-Change-Number: 19416 Gerrit-PatchSet: 17 Gerrit-Owner: lynxis lazus Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge Gerrit-Reviewer: lynxis lazus Gerrit-Reviewer: pespin Gerrit-MessageType: newpatchset
Change in libosmocore[master]: add osmo_sockaddr_local_ip() to determine the local address for a rem...
Hello pespin, laforge, Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/libosmocore/+/19416 to look at the new patch set (#14). Change subject: add osmo_sockaddr_local_ip() to determine the local address for a remote. .. add osmo_sockaddr_local_ip() to determine the local address for a remote. Similiar to osmo_sock_local_ip but for osmo_sockaddr. Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 --- M include/osmocom/core/socket.h M src/socket.c 2 files changed, 27 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/16/19416/14 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19416 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 Gerrit-Change-Number: 19416 Gerrit-PatchSet: 14 Gerrit-Owner: lynxis lazus Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge Gerrit-Reviewer: lynxis lazus Gerrit-Reviewer: pespin Gerrit-MessageType: newpatchset
Change in libosmocore[master]: add osmo_sockaddr_local_ip() to determine the local address for a rem...
Hello pespin, laforge, Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/libosmocore/+/19416 to look at the new patch set (#15). Change subject: add osmo_sockaddr_local_ip() to determine the local address for a remote. .. add osmo_sockaddr_local_ip() to determine the local address for a remote. Similiar to osmo_sock_local_ip but for osmo_sockaddr. Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 --- M include/osmocom/core/socket.h M src/socket.c 2 files changed, 27 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/16/19416/15 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19416 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 Gerrit-Change-Number: 19416 Gerrit-PatchSet: 15 Gerrit-Owner: lynxis lazus Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge Gerrit-Reviewer: lynxis lazus Gerrit-Reviewer: pespin Gerrit-MessageType: newpatchset
Change in libosmocore[master]: add osmo_sockaddr_local_ip() to determine the local address for a rem...
pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/19416 ) Change subject: add osmo_sockaddr_local_ip() to determine the local address for a remote. .. Patch Set 11: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19416 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 Gerrit-Change-Number: 19416 Gerrit-PatchSet: 11 Gerrit-Owner: lynxis lazus Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge Gerrit-Reviewer: lynxis lazus Gerrit-Reviewer: pespin Gerrit-Comment-Date: Mon, 17 Aug 2020 11:20:29 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
Change in libosmocore[master]: add osmo_sockaddr_local_ip() to determine the local address for a rem...
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/19416 ) Change subject: add osmo_sockaddr_local_ip() to determine the local address for a remote. .. Patch Set 11: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19416 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 Gerrit-Change-Number: 19416 Gerrit-PatchSet: 11 Gerrit-Owner: lynxis lazus Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge Gerrit-Reviewer: lynxis lazus Gerrit-Comment-Date: Wed, 12 Aug 2020 18:19:50 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
Change in libosmocore[master]: add osmo_sockaddr_local_ip() to determine the local address for a rem...
Hello Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/libosmocore/+/19416 to look at the new patch set (#11). Change subject: add osmo_sockaddr_local_ip() to determine the local address for a remote. .. add osmo_sockaddr_local_ip() to determine the local address for a remote. Similiar to osmo_sock_local_ip but for osmo_sockaddr. Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 --- M include/osmocom/core/socket.h M src/socket.c 2 files changed, 27 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/16/19416/11 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19416 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 Gerrit-Change-Number: 19416 Gerrit-PatchSet: 11 Gerrit-Owner: lynxis lazus Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: lynxis lazus Gerrit-CC: laforge Gerrit-MessageType: newpatchset
Change in libosmocore[master]: add osmo_sockaddr_local_ip() to determine the local address for a rem...
lynxis lazus has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/19416 ) Change subject: add osmo_sockaddr_local_ip() to determine the local address for a remote. .. Patch Set 10: (1 comment) https://gerrit.osmocom.org/c/libosmocore/+/19416/9/src/socket.c File src/socket.c: https://gerrit.osmocom.org/c/libosmocore/+/19416/9/src/socket.c@1567 PS9, Line 1567: remote_ip > ping? Done -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19416 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 Gerrit-Change-Number: 19416 Gerrit-PatchSet: 10 Gerrit-Owner: lynxis lazus Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: lynxis lazus Gerrit-CC: laforge Gerrit-Comment-Date: Mon, 10 Aug 2020 21:32:05 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: laforge Gerrit-MessageType: comment
Change in libosmocore[master]: add osmo_sockaddr_local_ip() to determine the local address for a rem...
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/19416 ) Change subject: add osmo_sockaddr_local_ip() to determine the local address for a remote. .. Patch Set 10: (1 comment) https://gerrit.osmocom.org/c/libosmocore/+/19416/9/src/socket.c File src/socket.c: https://gerrit.osmocom.org/c/libosmocore/+/19416/9/src/socket.c@1567 PS9, Line 1567: remote_ip > remote should be 'const' if it's an input argument. ping? -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19416 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 Gerrit-Change-Number: 19416 Gerrit-PatchSet: 10 Gerrit-Owner: lynxis lazus Gerrit-Reviewer: Jenkins Builder Gerrit-CC: laforge Gerrit-Comment-Date: Mon, 10 Aug 2020 20:14:37 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: laforge Gerrit-MessageType: comment
Change in libosmocore[master]: add osmo_sockaddr_local_ip() to determine the local address for a rem...
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/19416 ) Change subject: add osmo_sockaddr_local_ip() to determine the local address for a remote. .. Patch Set 9: (1 comment) also, see my earlier comment. https://gerrit.osmocom.org/c/libosmocore/+/19416/9/src/socket.c File src/socket.c: https://gerrit.osmocom.org/c/libosmocore/+/19416/9/src/socket.c@1567 PS9, Line 1567: remote_ip remote should be 'const' if it's an input argument. -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19416 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 Gerrit-Change-Number: 19416 Gerrit-PatchSet: 9 Gerrit-Owner: lynxis lazus Gerrit-Reviewer: Jenkins Builder Gerrit-CC: laforge Gerrit-Comment-Date: Mon, 03 Aug 2020 01:43:57 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Gerrit-MessageType: comment
Change in libosmocore[master]: add osmo_sockaddr_local_ip() to determine the local address for a rem...
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/19416 ) Change subject: add osmo_sockaddr_local_ip() to determine the local address for a remote. .. Patch Set 7: like in a previous patch: Doesn't it make sense to turn osmo_sock_local_ip() into a wrapper around the new osmo_sockaddr_local_ip? -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19416 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 Gerrit-Change-Number: 19416 Gerrit-PatchSet: 7 Gerrit-Owner: lynxis lazus Gerrit-Reviewer: Jenkins Builder Gerrit-CC: laforge Gerrit-Comment-Date: Tue, 28 Jul 2020 20:12:18 + Gerrit-HasComments: No Gerrit-Has-Labels: No Gerrit-MessageType: comment
Change in libosmocore[master]: add osmo_sockaddr_local_ip() to determine the local address for a rem...
lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/19416 ) Change subject: add osmo_sockaddr_local_ip() to determine the local address for a remote. .. add osmo_sockaddr_local_ip() to determine the local address for a remote. Similiar to osmo_sock_local_ip but for osmo_sockaddr. Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 --- M include/osmocom/core/socket.h M src/socket.c 2 files changed, 27 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/16/19416/1 diff --git a/include/osmocom/core/socket.h b/include/osmocom/core/socket.h index b162066..e5383ba 100644 --- a/include/osmocom/core/socket.h +++ b/include/osmocom/core/socket.h @@ -110,6 +110,8 @@ int osmo_sock_local_ip(char *local_ip, const char *remote_ip); +int osmo_sockaddr_local_ip(struct osmo_sockaddr *local_ip, + struct osmo_sockaddr *remote_ip); int osmo_sockaddr_cmp(struct osmo_sockaddr *a, struct osmo_sockaddr *b); /*! @} */ diff --git a/src/socket.c b/src/socket.c index 70f96c4..bc0f904 100644 --- a/src/socket.c +++ b/src/socket.c @@ -1529,6 +1529,31 @@ return 0; } +/*! Determine the matching local address for a given remote address. + * \param[out] local_ip caller provided memory for resulting local address + * \param[in] remote_ip remote address + * \returns 0 on success; negative otherwise + */ +int osmo_sockaddr_local_ip(struct osmo_sockaddr *local_ip, struct osmo_sockaddr *remote_ip) +{ + int sfd; + int rc; + socklen_t local_ip_len; + + sfd = osmo_sock_init3(SOCK_DGRAM, IPPROTO_UDP, NULL, remote_ip, OSMO_SOCK_F_CONNECT); + if (sfd < 0) + return -EINVAL; + + memset(local_ip, 0, sizeof(*local_ip)); + local_ip_len = sizeof(*local_ip); + rc = getsockname(sfd, (struct sockaddr *)local_ip, _ip_len); + close(sfd); + if (rc < 0) + return -EINVAL; + + return rc; +} + /*! Compare two osmo_sockaddr. Return 0 if they are same * \brief osmo_sockaddr_cmp * \param[in] a -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19416 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2 Gerrit-Change-Number: 19416 Gerrit-PatchSet: 1 Gerrit-Owner: lynxis lazus Gerrit-MessageType: newchange