Line | Count | Source |
1 | | /* -*- mode: c; c-file-style: "openbsd" -*- */ |
2 | | /* |
3 | | * Copyright (c) 2016 Vincent Bernat <bernat@luffy.cx> |
4 | | * |
5 | | * Permission to use, copy, modify, and/or distribute this software for any |
6 | | * purpose with or without fee is hereby granted, provided that the above |
7 | | * copyright notice and this permission notice appear in all copies. |
8 | | * |
9 | | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
10 | | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
11 | | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
12 | | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
13 | | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
14 | | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
15 | | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
16 | | */ |
17 | | |
18 | | #if HAVE_CONFIG_H |
19 | | # include <config.h> |
20 | | #endif |
21 | | |
22 | | #include <stdio.h> |
23 | | #include "compat/compat.h" |
24 | | #include "log.h" |
25 | | |
26 | | static void |
27 | | version_display_array(FILE *destination, const char *prefix, const char *const *items) |
28 | 0 | { |
29 | 0 | fprintf(destination, "%s", prefix); |
30 | 0 | size_t count = 0; |
31 | 0 | for (const char *const *p = items; *p; p++, count++) |
32 | 0 | fprintf(destination, "%s%s", count ? ", " : "", *p); |
33 | 0 | if (count == 0) |
34 | 0 | fprintf(destination, "(none)\n"); |
35 | 0 | else |
36 | 0 | fprintf(destination, "\n"); |
37 | 0 | } |
38 | | |
39 | | void |
40 | | version_display(FILE *destination, const char *progname, int verbose) |
41 | 0 | { |
42 | 0 | if (!verbose) { |
43 | 0 | fprintf(destination, "%s\n", PACKAGE_VERSION); |
44 | 0 | return; |
45 | 0 | } |
46 | | |
47 | 0 | const char *const lldp_features[] = { |
48 | 0 | #ifdef ENABLE_LLDPMED |
49 | 0 | "LLDP-MED", |
50 | 0 | #endif |
51 | 0 | #ifdef ENABLE_DOT1 |
52 | 0 | "Dot1", |
53 | 0 | #endif |
54 | 0 | #ifdef ENABLE_DOT3 |
55 | 0 | "Dot3", |
56 | 0 | #endif |
57 | 0 | #ifdef ENABLE_CUSTOM |
58 | 0 | "Custom TLV", |
59 | 0 | #endif |
60 | 0 | NULL |
61 | 0 | }; |
62 | 0 | const char *const protocols[] = { |
63 | 0 | #ifdef ENABLE_CDP |
64 | 0 | "CDP", |
65 | 0 | #endif |
66 | 0 | #ifdef ENABLE_FDP |
67 | 0 | "FDP", |
68 | 0 | #endif |
69 | 0 | #ifdef ENABLE_EDP |
70 | 0 | "EDP", |
71 | 0 | #endif |
72 | 0 | #ifdef ENABLE_SONMP |
73 | 0 | "SONMP", |
74 | 0 | #endif |
75 | 0 | NULL |
76 | 0 | }; |
77 | 0 | const char *const output_formats[] = { "TEXT", "KV", "JSON", |
78 | | #ifdef USE_XML |
79 | | "XML", |
80 | | #endif |
81 | 0 | NULL }; |
82 | |
|
83 | 0 | fprintf(destination, "%s %s\n", progname, PACKAGE_VERSION); |
84 | 0 | fprintf(destination, " Built on " BUILD_DATE "\n"); |
85 | 0 | fprintf(destination, "\n"); |
86 | | |
87 | | /* Features */ |
88 | 0 | if (!strcmp(progname, "lldpd")) { |
89 | 0 | version_display_array(destination, |
90 | 0 | "Additional LLDP features: ", lldp_features); |
91 | 0 | version_display_array(destination, |
92 | 0 | "Additional protocols: ", protocols); |
93 | 0 | fprintf(destination, |
94 | 0 | "SNMP support: " |
95 | | #ifdef USE_SNMP |
96 | | "yes\n" |
97 | | #else |
98 | 0 | "no\n" |
99 | 0 | #endif |
100 | 0 | ); |
101 | 0 | #ifdef HOST_OS_LINUX |
102 | 0 | fprintf(destination, |
103 | 0 | "Old kernel support: " |
104 | | # ifdef ENABLE_OLDIES |
105 | | "yes" |
106 | | # else |
107 | 0 | "no" |
108 | 0 | # endif |
109 | 0 | " (Linux " MIN_LINUX_KERNEL_VERSION "+)\n"); |
110 | 0 | #endif |
111 | 0 | #ifdef ENABLE_PRIVSEP |
112 | 0 | fprintf(destination, |
113 | 0 | "Privilege separation: " |
114 | 0 | "enabled\n"); |
115 | 0 | fprintf(destination, "Privilege separation user: " PRIVSEP_USER "\n"); |
116 | 0 | fprintf(destination, |
117 | 0 | "Privilege separation group: " PRIVSEP_GROUP "\n"); |
118 | 0 | fprintf(destination, |
119 | 0 | "Privilege separation chroot: " PRIVSEP_CHROOT "\n"); |
120 | | #else |
121 | | fprintf(destination, |
122 | | "Privilege separation: " |
123 | | "disabled\n"); |
124 | | #endif |
125 | 0 | fprintf(destination, "Configuration directory: " SYSCONFDIR "\n"); |
126 | 0 | } |
127 | |
|
128 | 0 | if (!strcmp(progname, "lldpcli")) { |
129 | 0 | version_display_array(destination, |
130 | 0 | "Additional output formats: ", output_formats); |
131 | 0 | } |
132 | |
|
133 | 0 | fprintf(destination, "\n"); |
134 | | |
135 | | /* Build */ |
136 | 0 | fprintf(destination, "C compiler command: %s\n", LLDP_CC); |
137 | 0 | fprintf(destination, "Linker command: %s\n", LLDP_LD); |
138 | 0 | } |