Signed-off-by: Richard Cochran <richardcoch...@gmail.com>
---
 util.c | 28 ++++++++++++++++++++++++++++
 util.h |  9 +++++++++
 2 files changed, 37 insertions(+)

diff --git a/util.c b/util.c
index 799147a..73fb37e 100644
--- a/util.c
+++ b/util.c
@@ -69,6 +69,34 @@ const char *ev_str[] = {
        "RS_PASSIVE",
 };
 
+int addreq(enum transport_type type, struct address *a, struct address *b)
+{
+       void *bufa, *bufb;
+       int len;
+
+       switch (type) {
+       case TRANS_UDP_IPV4:
+               bufa = &a->sin.sin_addr;
+               bufb = &b->sin.sin_addr;
+               len = sizeof(a->sin);
+               break;
+       case TRANS_IEEE_802_3:
+               bufa = &a->sll.sll_addr;
+               bufb = &b->sll.sll_addr;
+               len = MAC_LEN;
+               break;
+       case TRANS_UDS:
+       case TRANS_UDP_IPV6:
+       case TRANS_DEVICENET:
+       case TRANS_CONTROLNET:
+       case TRANS_PROFINET:
+       default:
+               pr_err("sorry, cannot compare addresses for this transport");
+               return 0;
+       }
+       return memcmp(bufa, bufb, len) == 0 ? 1 : 0;
+}
+
 char *bin2str_impl(Octet *data, int len, char *buf, int buf_len)
 {
        int i, offset = 0;
diff --git a/util.h b/util.h
index 4463b37..4becce1 100644
--- a/util.h
+++ b/util.h
@@ -41,6 +41,15 @@ extern const char *ps_str[];
  */
 extern const char *ev_str[];
 
+/**
+ * Compares two binary addresses for equality.
+ * @param type  One of the enumerated transport types.
+ * @param a     One address to compare.
+ * @param b     The second address to compare.
+ * @return      One if the addresses are identical, zero otherwise.
+ */
+int addreq(enum transport_type type, struct address *a, struct address *b);
+
 static inline uint16_t align16(uint16_t *p)
 {
        uint16_t v;
-- 
2.11.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to