From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Sat, 10 Sep 2022 10:38:50 +0000 (+0100) Subject: Ignore configure~ X-Git-Tag: 1.2~1^2~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=78eb65af051b3c2009b02ca87dd9e601d3e9261b;p=thirdparty%2Fnqptp.git Ignore configure~ --- diff --git a/.gitignore b/.gitignore index 1603619..f78c7e5 100644 --- a/.gitignore +++ b/.gitignore @@ -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 8865734..e82fd21 100644 --- 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. diff --git a/nqptp-utilities.c b/nqptp-utilities.c index 6a132f8..c3a5c7a 100644 --- a/nqptp-utilities.c +++ b/nqptp-utilities.c @@ -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 @@ -29,11 +29,11 @@ #endif #ifdef CONFIG_FOR_FREEBSD +#include +#include #include #include #include -#include -#include #endif #include // 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);