]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
Ignore configure~
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Sat, 10 Sep 2022 10:38:50 +0000 (11:38 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Sat, 10 Sep 2022 10:38:50 +0000 (11:38 +0100)
.gitignore
INSTALL
nqptp-utilities.c

index 16036191a2eed9d3d07d0b6c1270f958f5611082..f78c7e598d861dbc1a9ec279b86a895b986c6b07 100644 (file)
@@ -1,6 +1,7 @@
 # http://www.gnu.org/software/automake
 
 Makefile.in
+configure~
 /ar-lib
 /mdate-sh
 /py-compile
diff --git a/INSTALL b/INSTALL
index 8865734f81b136629e961c230380423899c75794..e82fd21de2eae1cb6cbb75aeee697cdce8da3a59 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -1,8 +1,8 @@
 Installation Instructions
 *************************
 
-   Copyright (C) 1994-1996, 1999-2002, 2004-2016 Free Software
-Foundation, Inc.
+   Copyright (C) 1994-1996, 1999-2002, 2004-2017, 2020-2021 Free
+Software Foundation, Inc.
 
    Copying and distribution of this file, with or without modification,
 are permitted in any medium without royalty provided the copyright
@@ -225,7 +225,7 @@ order to use an ANSI C compiler:
 
 and if that doesn't work, install pre-built binaries of GCC for HP-UX.
 
-   HP-UX 'make' updates targets which have the same time stamps as their
+   HP-UX 'make' updates targets which have the same timestamps as their
 prerequisites, which makes it generally unusable when shipped generated
 files such as 'configure' are involved.  Use GNU 'make' instead.
 
index 6a132f8366a6dd30b7909d877d8208dc3501040e..c3a5c7a623f28eb2bdbec4789d71f8f3e06b91fd 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of the nqptp distribution (https://github.com/mikebrady/nqptp).
- * Copyright (c) 2021 Mike Brady.
+ * Copyright (c) 2021-2022 Mike Brady.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #endif
 
 #ifdef CONFIG_FOR_FREEBSD
+#include <unistd.h>
+#include <sys/types.h>
 #include <net/if_dl.h>
 #include <net/if_types.h>
 #include <sys/socket.h>
-#include <sys/types.h>
-#include <unistd.h>
 #endif
 
 #include <netdb.h>  // getaddrinfo etc.
@@ -157,57 +157,86 @@ void debug_print_buffer(int level, char *buf, size_t buf_len) {
   }
 }
 
-uint64_t get_self_clock_id() {
-  // make up a clock ID based on an interfaces' MAC
-  unsigned char local_clock_id[8];
-  int len = 0;
+// pass in an array of bytes and a max_length, or a max length of 0 for unlimited
+// the actual size will be returned
+
+int get_device_id(uint8_t *id, int *int_length) {
+  int max_length = *int_length;
+  int response = -1;
   struct ifaddrs *ifaddr = NULL;
   struct ifaddrs *ifa = NULL;
-  int status;
-  if ((status = getifaddrs(&ifaddr) == -1)) {
-    die("getifaddrs: %s", gai_strerror(status));
-  } else {
+  int i = 0;
+  uint8_t *t = id;
+  
+  // clear the buffer if non zero length passed in
+  for (i = 0; i < max_length; i++) {
+    *t++ = 0;
+  }
+
+  // look for a useful MAC address
+  if (getifaddrs(&ifaddr) != -1) {
+    t = id;
     int found = 0;
-    for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+    
+    for (ifa = ifaddr; ((ifa != NULL) && (found == 0)); ifa = ifa->ifa_next) {
 #ifdef AF_PACKET
       if ((ifa->ifa_addr) && (ifa->ifa_addr->sa_family == AF_PACKET)) {
         struct sockaddr_ll *s = (struct sockaddr_ll *)ifa->ifa_addr;
-        if ((strcmp(ifa->ifa_name, "lo") != 0) && (found == 0)) {
-          len = s->sll_halen;
-          memcpy(local_clock_id, &s->sll_addr, len);
+        if ((strcmp(ifa->ifa_name, "lo") != 0)) {
           found = 1;
+          if ((max_length == 0) || (s->sll_halen < max_length)) {
+            max_length = s->sll_halen;
+            *int_length = max_length;
+          }
+          for (i = 0; i < max_length; i++) {
+            *t++ = s->sll_addr[i];
+          }
         }
       }
 #else
-// This AF_LINK stuff hasn't been tested!
 #ifdef AF_LINK
       struct sockaddr_dl *sdl = (struct sockaddr_dl *)ifa->ifa_addr;
       if ((sdl) && (sdl->sdl_family == AF_LINK)) {
         if (sdl->sdl_type == IFT_ETHER) {
-          char *s = LLADDR(sdl);
-          int i;
-          for (i = 0; i < sdl->sdl_alen; i++) {
-            debug(1, "char %d: \"%c\".", i, *s);
-            // *t++ = (uint8_t)*s++;
-          }
           found = 1;
+          if ((max_length == 0) || (sdl->sdl_alen < max_length)) {
+            max_length = sdl->sdl_alen;
+            *int_length = max_length;
+          }
+          uint8_t *s = (uint8_t *)LLADDR(sdl);
+          for (i = 0; i < max_length; i++) {
+            *t++ = *s++;
+          }
         }
       }
-
 #endif
 #endif
+
     }
+    if (found != 0)
+      response = 0;
     freeifaddrs(ifaddr);
   }
-  // if the length of the MAC address is 6 we need to doctor it a little
-  // See Section 7.5.2.2.2 IEEE EUI-64 clockIdentity values, NOTE 2
-
-  if (len == 6) { // i.e. an EUI-48 MAC Address
-    local_clock_id[7] = local_clock_id[5];
-    local_clock_id[6] = local_clock_id[4];
-    local_clock_id[5] = local_clock_id[3];
-    local_clock_id[3] = 0xFF;
-    local_clock_id[4] = 0xFE;
+  return response;
+}
+
+
+uint64_t get_self_clock_id() {
+  // make up a clock ID based on an interface's MAC
+  int local_clock_id_size = 8; // don't exceed this
+  uint8_t local_clock_id[local_clock_id_size];
+  memset(local_clock_id,0,local_clock_id_size);
+  if (get_device_id(local_clock_id,&local_clock_id_size) == 0) {
+    // if the length of the MAC address is 6 we need to doctor it a little
+    // See Section 7.5.2.2.2 IEEE EUI-64 clockIdentity values, NOTE 2
+
+    if (local_clock_id_size == 6) { // i.e. an EUI-48 MAC Address
+      local_clock_id[7] = local_clock_id[5];
+      local_clock_id[6] = local_clock_id[4];
+      local_clock_id[5] = local_clock_id[3];
+      local_clock_id[3] = 0xFF;
+      local_clock_id[4] = 0xFE;
+    }
   }
   // convert to host byte order
   return nctoh64(local_clock_id);