summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2016-02-22 17:38:34 +0100
committerTom Gundersen <teg@jklm.no>2016-02-22 17:38:34 +0100
commit7c7c0cbe640e33e5f57b24d0281564724b3eaeeb (patch)
tree478c558c880ef1082eda62b6ee3208b29fe98832 /src/basic
parenta4ae7f1d739cc011b5312a8bfba99971bce0e7c3 (diff)
parentda6c766d539dc38dbabf401be31180ca4691215f (diff)
Merge pull request #2685 from poettering/lldp-fixes2
lldp fixes, second iteration
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/btrfs-util.h4
-rw-r--r--src/basic/ether-addr-util.c23
-rw-r--r--src/basic/ether-addr-util.h5
-rw-r--r--src/basic/gunicode.h4
-rw-r--r--src/basic/hostname-util.c28
-rw-r--r--src/basic/hostname-util.h1
-rw-r--r--src/basic/login-util.h4
-rw-r--r--src/basic/missing.h5
-rw-r--r--src/basic/sigbus.h4
9 files changed, 69 insertions, 9 deletions
diff --git a/src/basic/btrfs-util.h b/src/basic/btrfs-util.h
index 37802c2565..1d852d502c 100644
--- a/src/basic/btrfs-util.h
+++ b/src/basic/btrfs-util.h
@@ -1,3 +1,5 @@
+#pragma once
+
/***
This file is part of systemd.
@@ -17,8 +19,6 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#pragma once
-
#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
diff --git a/src/basic/ether-addr-util.c b/src/basic/ether-addr-util.c
index ded6d31f4b..d2c030903b 100644
--- a/src/basic/ether-addr-util.c
+++ b/src/basic/ether-addr-util.c
@@ -42,3 +42,26 @@ char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR
return buffer;
}
+
+bool ether_addr_is_null(const struct ether_addr *addr) {
+ assert(addr);
+
+ return addr->ether_addr_octet[0] == 0 &&
+ addr->ether_addr_octet[1] == 0 &&
+ addr->ether_addr_octet[2] == 0 &&
+ addr->ether_addr_octet[3] == 0 &&
+ addr->ether_addr_octet[4] == 0 &&
+ addr->ether_addr_octet[5] == 0;
+}
+
+bool ether_addr_equal(const struct ether_addr *a, const struct ether_addr *b) {
+ assert(a);
+ assert(b);
+
+ return a->ether_addr_octet[0] == b->ether_addr_octet[0] &&
+ a->ether_addr_octet[1] == b->ether_addr_octet[1] &&
+ a->ether_addr_octet[2] == b->ether_addr_octet[2] &&
+ a->ether_addr_octet[3] == b->ether_addr_octet[3] &&
+ a->ether_addr_octet[4] == b->ether_addr_octet[4] &&
+ a->ether_addr_octet[5] == b->ether_addr_octet[5];
+}
diff --git a/src/basic/ether-addr-util.h b/src/basic/ether-addr-util.h
index 4487149efd..00c5159fe8 100644
--- a/src/basic/ether-addr-util.h
+++ b/src/basic/ether-addr-util.h
@@ -20,10 +20,13 @@
***/
#include <net/ethernet.h>
+#include <stdbool.h>
#define ETHER_ADDR_FORMAT_STR "%02X%02X%02X%02X%02X%02X"
#define ETHER_ADDR_FORMAT_VAL(x) (x).ether_addr_octet[0], (x).ether_addr_octet[1], (x).ether_addr_octet[2], (x).ether_addr_octet[3], (x).ether_addr_octet[4], (x).ether_addr_octet[5]
#define ETHER_ADDR_TO_STRING_MAX (3*6)
-
char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR_TO_STRING_MAX]);
+
+bool ether_addr_is_null(const struct ether_addr *addr);
+bool ether_addr_equal(const struct ether_addr *a, const struct ether_addr *b);
diff --git a/src/basic/gunicode.h b/src/basic/gunicode.h
index b03aa43160..5975bc8fc9 100644
--- a/src/basic/gunicode.h
+++ b/src/basic/gunicode.h
@@ -1,11 +1,11 @@
+#pragma once
+
/* gunicode.h - Unicode manipulation functions
*
* Copyright (C) 1999, 2000 Tom Tromey
* Copyright 2000, 2005 Red Hat, Inc.
*/
-#pragma once
-
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
diff --git a/src/basic/hostname-util.c b/src/basic/hostname-util.c
index 57031b645c..f900c509a3 100644
--- a/src/basic/hostname-util.c
+++ b/src/basic/hostname-util.c
@@ -48,6 +48,9 @@ bool hostname_is_set(void) {
char* gethostname_malloc(void) {
struct utsname u;
+ /* This call tries to return something useful, either the actual hostname or it makes something up. The only
+ * reason it might mail is OOM. It might even return "localhost" if that's set. */
+
assert_se(uname(&u) >= 0);
if (isempty(u.nodename) || streq(u.nodename, "(none)"))
@@ -56,6 +59,31 @@ char* gethostname_malloc(void) {
return strdup(u.nodename);
}
+int gethostname_strict(char **ret) {
+ struct utsname u;
+ char *k;
+
+ /* This call will rather fail than make up a name. It will not return "localhost" either. */
+
+ assert_se(uname(&u) >= 0);
+
+ if (isempty(u.nodename))
+ return -ENXIO;
+
+ if (streq(u.nodename, "(none)"))
+ return -ENXIO;
+
+ if (is_localhost(u.nodename))
+ return -ENXIO;
+
+ k = strdup(u.nodename);
+ if (!k)
+ return -ENOMEM;
+
+ *ret = k;
+ return 0;
+}
+
static bool hostname_valid_char(char c) {
return
(c >= 'a' && c <= 'z') ||
diff --git a/src/basic/hostname-util.h b/src/basic/hostname-util.h
index d062eddea1..7af4e6c7ec 100644
--- a/src/basic/hostname-util.h
+++ b/src/basic/hostname-util.h
@@ -26,6 +26,7 @@
bool hostname_is_set(void);
char* gethostname_malloc(void);
+int gethostname_strict(char **ret);
bool hostname_is_valid(const char *s, bool allow_trailing_dot) _pure_;
char* hostname_cleanup(char *s);
diff --git a/src/basic/login-util.h b/src/basic/login-util.h
index 89a337d7c1..b01ee25c88 100644
--- a/src/basic/login-util.h
+++ b/src/basic/login-util.h
@@ -1,3 +1,5 @@
+#pragma once
+
/***
This file is part of systemd.
@@ -17,8 +19,6 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#pragma once
-
#include <stdbool.h>
#include <unistd.h>
diff --git a/src/basic/missing.h b/src/basic/missing.h
index 88ecb4ac01..417604aa64 100644
--- a/src/basic/missing.h
+++ b/src/basic/missing.h
@@ -31,6 +31,7 @@
#include <linux/neighbour.h>
#include <linux/oom.h>
#include <linux/rtnetlink.h>
+#include <net/ethernet.h>
#include <stdlib.h>
#include <sys/resource.h>
#include <sys/syscall.h>
@@ -1171,4 +1172,8 @@ static inline key_serial_t request_key(const char *type, const char *description
#define char16_t uint16_t
#endif
+#ifndef ETHERTYPE_LLDP
+#define ETHERTYPE_LLDP 0x88cc
+#endif
+
#endif
diff --git a/src/basic/sigbus.h b/src/basic/sigbus.h
index cce9eb201b..980243d9ce 100644
--- a/src/basic/sigbus.h
+++ b/src/basic/sigbus.h
@@ -1,3 +1,5 @@
+#pragma once
+
/***
This file is part of systemd.
@@ -17,8 +19,6 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#pragma once
-
void sigbus_install(void);
void sigbus_reset(void);