This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
lynxis lazus gerrit-no-reply at lists.osmocom.orglynxis lazus has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/19415 ) Change subject: socket: add osmo_sockaddr_cmp() ...................................................................... socket: add osmo_sockaddr_cmp() Compare two osmo_sockaddr. Change-Id: I2d12ebae2710ffd17cf071e6ada0804e73f87dd6 --- M include/osmocom/core/socket.h M src/socket.c 2 files changed, 31 insertions(+), 0 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved pespin: Looks good to me, approved daniel: Looks good to me, but someone else must approve diff --git a/include/osmocom/core/socket.h b/include/osmocom/core/socket.h index 4441449..e417f42 100644 --- a/include/osmocom/core/socket.h +++ b/include/osmocom/core/socket.h @@ -113,5 +113,7 @@ int osmo_sock_local_ip(char *local_ip, const char *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 6c06063..803af31 100644 --- a/src/socket.c +++ b/src/socket.c @@ -1662,6 +1662,35 @@ return 0; } +/*! Compare two osmo_sockaddr. + * \param[in] a + * \param[in] b + * \return 0 if a and b are equal. Otherwise it follows memcmp() + */ +int osmo_sockaddr_cmp(struct osmo_sockaddr *a, struct osmo_sockaddr *b) +{ + if (a == b) + return 0; + if (!a) + return 1; + if (!b) + return -1; + + if (a->u.sa.sa_family != b->u.sa.sa_family) { + return OSMO_CMP(a->u.sa.sa_family, b->u.sa.sa_family); + } + + switch (a->u.sa.sa_family) { + case AF_INET: + return memcmp(&a->u.sin, &b->u.sin, sizeof(struct sockaddr_in)); + case AF_INET6: + return memcmp(&a->u.sin6, &b->u.sin6, sizeof(struct sockaddr_in6)); + default: + /* fallback to memcmp for remaining AF over the full osmo_sockaddr length */ + return memcmp(a, b, sizeof(struct osmo_sockaddr)); + } +} + #endif /* HAVE_SYS_SOCKET_H */ /*! @} */ -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19415 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I2d12ebae2710ffd17cf071e6ada0804e73f87dd6 Gerrit-Change-Number: 19415 Gerrit-PatchSet: 19 Gerrit-Owner: lynxis lazus <lynxis at fe80.eu> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel <dwillmann at sysmocom.de> Gerrit-Reviewer: laforge <laforge at osmocom.org> Gerrit-Reviewer: lynxis lazus <lynxis at fe80.eu> Gerrit-Reviewer: neels <nhofmeyr at sysmocom.de> Gerrit-Reviewer: pespin <pespin at sysmocom.de> Gerrit-MessageType: merged -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200906/943f7f06/attachment.htm>