-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathifconfig-quiet.patch
More file actions
149 lines (136 loc) · 4.39 KB
/
ifconfig-quiet.patch
File metadata and controls
149 lines (136 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
--- kinit/ipconfig/main.c.fix5 2012-02-09 18:24:38.502496983 +0400
+++ kinit/ipconfig/main.c 2012-02-09 18:27:25.014496980 +0400
@@ -1,8 +1,9 @@
#include <poll.h>
#include <limits.h>
#include <setjmp.h>
#include <stdio.h>
+#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <arpa/inet.h>
@@ -29,8 +30,9 @@ static unsigned int default_caps = CAP_D
static int loop_timeout = -1;
static int configured;
static int bringup_first = 0;
static int do_readonly = 0;
+static int do_quiet = 0;
/* DHCP vendor class identifier */
char vendor_class_identifier[260];
int vendor_class_identifier_len;
@@ -53,10 +55,22 @@ static inline const char *my_inet_ntoa(u
return inet_ntoa(a);
}
+static void message(char *fmt, ...)
+{
+ if (do_quiet)
+ return;
+ va_list ap;
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+}
+
static void print_device_config(struct netdev *dev)
{
+ if (do_quiet)
+ return;
printf("IP-Config: %s complete (from %s):\n", dev->name,
my_inet_ntoa(dev->serverid ? dev->serverid : dev->ip_server));
printf(" address: %-16s ", my_inet_ntoa(dev->ip_addr));
printf("broadcast: %-16s ", my_inet_ntoa(dev->ip_broadcast));
@@ -80,20 +94,20 @@ static void configure_device(struct netd
if (do_not_config)
return;
if (netdev_setmtu(dev))
- printf("IP-Config: failed to set MTU on %s to %u\n",
+ message("IP-Config: failed to set MTU on %s to %u\n",
dev->name, dev->mtu);
if (netdev_setaddress(dev))
- printf("IP-Config: failed to set addresses on %s\n",
+ message("IP-Config: failed to set addresses on %s\n",
dev->name);
if (netdev_setdefaultroute(dev))
- printf("IP-Config: failed to set default route on %s\n",
+ message("IP-Config: failed to set default route on %s\n",
dev->name);
if (dev->hostname[0] &&
sethostname(dev->hostname, strlen(dev->hostname)))
- printf("IP-Config: failed to set hostname '%s' from %s\n",
+ message("IP-Config: failed to set hostname '%s' from %s\n",
dev->hostname, dev->name);
}
/*
@@ -170,15 +184,15 @@ static uint32_t inet_class_netmask(uint3
static void postprocess_device(struct netdev *dev)
{
if (dev->ip_netmask == INADDR_ANY) {
dev->ip_netmask = inet_class_netmask(dev->ip_addr);
- printf("IP-Config: %s guessed netmask %s\n",
+ message("IP-Config: %s guessed netmask %s\n",
dev->name, my_inet_ntoa(dev->ip_netmask));
}
if (dev->ip_broadcast == INADDR_ANY) {
dev->ip_broadcast =
(dev->ip_addr & dev->ip_netmask) | ~dev->ip_netmask;
- printf("IP-Config: %s guessed broadcast address %s\n",
+ message("IP-Config: %s guessed broadcast address %s\n",
dev->name, my_inet_ntoa(dev->ip_broadcast));
}
}
@@ -418,9 +432,9 @@ static int loop(void)
}
if (loop_timeout >= 0 &&
now.tv_sec - start >= loop_timeout) {
- printf("IP-Config: no response after %d "
+ message("IP-Config: no response after %d "
"secs - giving up\n", loop_timeout);
rc = -1;
goto bail;
}
@@ -638,12 +652,12 @@ static struct netdev *add_device(const c
if (bootp_init_if(dev) == -1)
goto bail;
- printf("IP-Config: %s hardware address", dev->name);
+ message("IP-Config: %s hardware address", dev->name);
for (i = 0; i < dev->hwlen; i++)
- printf("%c%02x", i == 0 ? ' ' : ':', dev->hwaddr[i]);
- printf(" mtu %d%s%s\n", dev->mtu,
+ message("%c%02x", i == 0 ? ' ' : ':', dev->hwaddr[i]);
+ message(" mtu %d%s%s\n", dev->mtu,
dev->caps & CAP_DHCP ? " DHCP" :
dev->caps & CAP_BOOTP ? " BOOTP" : "",
dev->caps & CAP_RARP ? " RARP" : "");
return dev;
@@ -765,9 +779,9 @@ int ipconfig_main(int argc, char *argv[]
/* Default vendor identifier */
set_vendor_identifier("Linux ipconfig");
do {
- c = getopt(argc, argv, "c:d:i:onp:rt:");
+ c = getopt(argc, argv, "c:d:i:onp:rt:q");
if (c == EOF)
break;
switch (c) {
@@ -805,8 +819,11 @@ int ipconfig_main(int argc, char *argv[]
break;
case 'r':
do_readonly = 1;
break;
+ case 'q':
+ do_quiet = 1;
+ break;
case 'd':
dev = add_device(optarg);
if (dev)
bringup_device(dev);
@@ -825,9 +842,9 @@ int ipconfig_main(int argc, char *argv[]
}
if (check_autoconfig()) {
if (cfg_local_port != LOCAL_PORT) {
- printf("IP-Config: binding source port to %d, "
+ message("IP-Config: binding source port to %d, "
"dest to %d\n",
cfg_local_port, cfg_remote_port);
}
err = loop();