aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2002-11-28 12:19:51 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2002-11-28 12:19:51 +0000
commit8b6024449f9b2eb69bf4b36e1d7e9c2b7e7b30fc (patch)
tree27096d526b4c10aa75b3f60591d20b8a4393e7c3
parente3e2a7b41cf130004c2be3402c34646dc0ef3e24 (diff)
downloadbusybox-w32-8b6024449f9b2eb69bf4b36e1d7e9c2b7e7b30fc.tar.gz
busybox-w32-8b6024449f9b2eb69bf4b36e1d7e9c2b7e7b30fc.tar.bz2
busybox-w32-8b6024449f9b2eb69bf4b36e1d7e9c2b7e7b30fc.zip
Cleanup error messages
-rw-r--r--networking/libiproute/iptunnel.c74
1 files changed, 36 insertions, 38 deletions
diff --git a/networking/libiproute/iptunnel.c b/networking/libiproute/iptunnel.c
index beb8bb675..58ec7cce6 100644
--- a/networking/libiproute/iptunnel.c
+++ b/networking/libiproute/iptunnel.c
@@ -41,13 +41,11 @@ static int do_ioctl_get_ifindex(char *dev)
41{ 41{
42 struct ifreq ifr; 42 struct ifreq ifr;
43 int fd; 43 int fd;
44 int err;
45 44
46 strcpy(ifr.ifr_name, dev); 45 strcpy(ifr.ifr_name, dev);
47 fd = socket(AF_INET, SOCK_DGRAM, 0); 46 fd = socket(AF_INET, SOCK_DGRAM, 0);
48 err = ioctl(fd, SIOCGIFINDEX, &ifr); 47 if (ioctl(fd, SIOCGIFINDEX, &ifr)) {
49 if (err) { 48 perror_msg("ioctl");
50 perror("ioctl");
51 return 0; 49 return 0;
52 } 50 }
53 close(fd); 51 close(fd);
@@ -58,13 +56,11 @@ static int do_ioctl_get_iftype(char *dev)
58{ 56{
59 struct ifreq ifr; 57 struct ifreq ifr;
60 int fd; 58 int fd;
61 int err;
62 59
63 strcpy(ifr.ifr_name, dev); 60 strcpy(ifr.ifr_name, dev);
64 fd = socket(AF_INET, SOCK_DGRAM, 0); 61 fd = socket(AF_INET, SOCK_DGRAM, 0);
65 err = ioctl(fd, SIOCGIFHWADDR, &ifr); 62 if (ioctl(fd, SIOCGIFHWADDR, &ifr)) {
66 if (err) { 63 perror_msg("ioctl");
67 perror("ioctl");
68 return -1; 64 return -1;
69 } 65 }
70 close(fd); 66 close(fd);
@@ -72,17 +68,15 @@ static int do_ioctl_get_iftype(char *dev)
72} 68}
73 69
74 70
75static char * do_ioctl_get_ifname(int idx) 71static char *do_ioctl_get_ifname(int idx)
76{ 72{
77 static struct ifreq ifr; 73 static struct ifreq ifr;
78 int fd; 74 int fd;
79 int err;
80 75
81 ifr.ifr_ifindex = idx; 76 ifr.ifr_ifindex = idx;
82 fd = socket(AF_INET, SOCK_DGRAM, 0); 77 fd = socket(AF_INET, SOCK_DGRAM, 0);
83 err = ioctl(fd, SIOCGIFNAME, &ifr); 78 if (ioctl(fd, SIOCGIFNAME, &ifr)) {
84 if (err) { 79 perror_msg("ioctl");
85 perror("ioctl");
86 return NULL; 80 return NULL;
87 } 81 }
88 close(fd); 82 close(fd);
@@ -101,8 +95,9 @@ static int do_get_ioctl(char *basedev, struct ip_tunnel_parm *p)
101 ifr.ifr_ifru.ifru_data = (void*)p; 95 ifr.ifr_ifru.ifru_data = (void*)p;
102 fd = socket(AF_INET, SOCK_DGRAM, 0); 96 fd = socket(AF_INET, SOCK_DGRAM, 0);
103 err = ioctl(fd, SIOCGETTUNNEL, &ifr); 97 err = ioctl(fd, SIOCGETTUNNEL, &ifr);
104 if (err) 98 if (err) {
105 perror("ioctl"); 99 perror_msg("ioctl");
100 }
106 close(fd); 101 close(fd);
107 return err; 102 return err;
108} 103}
@@ -113,15 +108,17 @@ static int do_add_ioctl(int cmd, char *basedev, struct ip_tunnel_parm *p)
113 int fd; 108 int fd;
114 int err; 109 int err;
115 110
116 if (cmd == SIOCCHGTUNNEL && p->name[0]) 111 if (cmd == SIOCCHGTUNNEL && p->name[0]) {
117 strcpy(ifr.ifr_name, p->name); 112 strcpy(ifr.ifr_name, p->name);
118 else 113 } else {
119 strcpy(ifr.ifr_name, basedev); 114 strcpy(ifr.ifr_name, basedev);
115 }
120 ifr.ifr_ifru.ifru_data = (void*)p; 116 ifr.ifr_ifru.ifru_data = (void*)p;
121 fd = socket(AF_INET, SOCK_DGRAM, 0); 117 fd = socket(AF_INET, SOCK_DGRAM, 0);
122 err = ioctl(fd, cmd, &ifr); 118 err = ioctl(fd, cmd, &ifr);
123 if (err) 119 if (err) {
124 perror("ioctl"); 120 perror_msg("ioctl");
121 }
125 close(fd); 122 close(fd);
126 return err; 123 return err;
127} 124}
@@ -132,15 +129,17 @@ static int do_del_ioctl(char *basedev, struct ip_tunnel_parm *p)
132 int fd; 129 int fd;
133 int err; 130 int err;
134 131
135 if (p->name[0]) 132 if (p->name[0]) {
136 strcpy(ifr.ifr_name, p->name); 133 strcpy(ifr.ifr_name, p->name);
137 else 134 } else {
138 strcpy(ifr.ifr_name, basedev); 135 strcpy(ifr.ifr_name, basedev);
136 }
139 ifr.ifr_ifru.ifru_data = (void*)p; 137 ifr.ifr_ifru.ifru_data = (void*)p;
140 fd = socket(AF_INET, SOCK_DGRAM, 0); 138 fd = socket(AF_INET, SOCK_DGRAM, 0);
141 err = ioctl(fd, SIOCDELTUNNEL, &ifr); 139 err = ioctl(fd, SIOCDELTUNNEL, &ifr);
142 if (err) 140 if (err) {
143 perror("ioctl"); 141 perror_msg("ioctl");
142 }
144 close(fd); 143 close(fd);
145 return err; 144 return err;
146} 145}
@@ -149,7 +148,6 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
149{ 148{
150 int count = 0; 149 int count = 0;
151 char medium[IFNAMSIZ]; 150 char medium[IFNAMSIZ];
152
153 memset(p, 0, sizeof(*p)); 151 memset(p, 0, sizeof(*p));
154 memset(&medium, 0, sizeof(medium)); 152 memset(&medium, 0, sizeof(medium));
155 153
@@ -166,26 +164,26 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
166 if (strcmp(*argv, "ipip") == 0 || 164 if (strcmp(*argv, "ipip") == 0 ||
167 strcmp(*argv, "ip/ip") == 0) { 165 strcmp(*argv, "ip/ip") == 0) {
168 if (p->iph.protocol && p->iph.protocol != IPPROTO_IPIP) { 166 if (p->iph.protocol && p->iph.protocol != IPPROTO_IPIP) {
169 fprintf(stderr,"You managed to ask for more than one tunnel mode.\n"); 167 error_msg("You managed to ask for more than one tunnel mode.");
170 exit(-1); 168 exit(-1);
171 } 169 }
172 p->iph.protocol = IPPROTO_IPIP; 170 p->iph.protocol = IPPROTO_IPIP;
173 } else if (strcmp(*argv, "gre") == 0 || 171 } else if (strcmp(*argv, "gre") == 0 ||
174 strcmp(*argv, "gre/ip") == 0) { 172 strcmp(*argv, "gre/ip") == 0) {
175 if (p->iph.protocol && p->iph.protocol != IPPROTO_GRE) { 173 if (p->iph.protocol && p->iph.protocol != IPPROTO_GRE) {
176 fprintf(stderr,"You managed to ask for more than one tunnel mode.\n"); 174 error_msg("You managed to ask for more than one tunnel mode.");
177 exit(-1); 175 exit(-1);
178 } 176 }
179 p->iph.protocol = IPPROTO_GRE; 177 p->iph.protocol = IPPROTO_GRE;
180 } else if (strcmp(*argv, "sit") == 0 || 178 } else if (strcmp(*argv, "sit") == 0 ||
181 strcmp(*argv, "ipv6/ip") == 0) { 179 strcmp(*argv, "ipv6/ip") == 0) {
182 if (p->iph.protocol && p->iph.protocol != IPPROTO_IPV6) { 180 if (p->iph.protocol && p->iph.protocol != IPPROTO_IPV6) {
183 fprintf(stderr,"You managed to ask for more than one tunnel mode.\n"); 181 error_msg("You managed to ask for more than one tunnel mode.");
184 exit(-1); 182 exit(-1);
185 } 183 }
186 p->iph.protocol = IPPROTO_IPV6; 184 p->iph.protocol = IPPROTO_IPV6;
187 } else { 185 } else {
188 fprintf(stderr,"Cannot guess tunnel mode.\n"); 186 error_msg("Cannot guess tunnel mode.");
189 exit(-1); 187 exit(-1);
190 } 188 }
191 } else if (strcmp(*argv, "key") == 0) { 189 } else if (strcmp(*argv, "key") == 0) {
@@ -197,7 +195,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
197 p->i_key = p->o_key = get_addr32(*argv); 195 p->i_key = p->o_key = get_addr32(*argv);
198 else { 196 else {
199 if (get_unsigned(&uval, *argv, 0)<0) { 197 if (get_unsigned(&uval, *argv, 0)<0) {
200 fprintf(stderr, "invalid value of \"key\"\n"); 198 error_msg("invalid value of \"key\"");
201 exit(-1); 199 exit(-1);
202 } 200 }
203 p->i_key = p->o_key = htonl(uval); 201 p->i_key = p->o_key = htonl(uval);
@@ -210,7 +208,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
210 p->o_key = get_addr32(*argv); 208 p->o_key = get_addr32(*argv);
211 else { 209 else {
212 if (get_unsigned(&uval, *argv, 0)<0) { 210 if (get_unsigned(&uval, *argv, 0)<0) {
213 fprintf(stderr, "invalid value of \"ikey\"\n"); 211 error_msg("invalid value of \"ikey\"");
214 exit(-1); 212 exit(-1);
215 } 213 }
216 p->i_key = htonl(uval); 214 p->i_key = htonl(uval);
@@ -223,7 +221,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
223 p->o_key = get_addr32(*argv); 221 p->o_key = get_addr32(*argv);
224 else { 222 else {
225 if (get_unsigned(&uval, *argv, 0)<0) { 223 if (get_unsigned(&uval, *argv, 0)<0) {
226 fprintf(stderr, "invalid value of \"okey\"\n"); 224 error_msg("invalid value of \"okey\"");
227 exit(-1); 225 exit(-1);
228 } 226 }
229 p->o_key = htonl(uval); 227 p->o_key = htonl(uval);
@@ -308,7 +306,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
308 306
309 if (p->iph.protocol == IPPROTO_IPIP || p->iph.protocol == IPPROTO_IPV6) { 307 if (p->iph.protocol == IPPROTO_IPIP || p->iph.protocol == IPPROTO_IPV6) {
310 if ((p->i_flags & GRE_KEY) || (p->o_flags & GRE_KEY)) { 308 if ((p->i_flags & GRE_KEY) || (p->o_flags & GRE_KEY)) {
311 fprintf(stderr, "Keys are not allowed with ipip and sit.\n"); 309 error_msg("Keys are not allowed with ipip and sit.");
312 return -1; 310 return -1;
313 } 311 }
314 } 312 }
@@ -328,7 +326,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
328 p->o_flags |= GRE_KEY; 326 p->o_flags |= GRE_KEY;
329 } 327 }
330 if (IN_MULTICAST(ntohl(p->iph.daddr)) && !p->iph.saddr) { 328 if (IN_MULTICAST(ntohl(p->iph.daddr)) && !p->iph.saddr) {
331 fprintf(stderr, "Broadcast tunnel requires a source address.\n"); 329 error_msg("Broadcast tunnel requires a source address.");
332 return -1; 330 return -1;
333 } 331 }
334 return 0; 332 return 0;
@@ -343,7 +341,7 @@ static int do_add(int cmd, int argc, char **argv)
343 return -1; 341 return -1;
344 342
345 if (p.iph.ttl && p.iph.frag_off == 0) { 343 if (p.iph.ttl && p.iph.frag_off == 0) {
346 fprintf(stderr, "ttl != 0 and noptmudisc are incompatible\n"); 344 error_msg("ttl != 0 and noptmudisc are incompatible");
347 return -1; 345 return -1;
348 } 346 }
349 347
@@ -355,7 +353,7 @@ static int do_add(int cmd, int argc, char **argv)
355 case IPPROTO_IPV6: 353 case IPPROTO_IPV6:
356 return do_add_ioctl(cmd, "sit0", &p); 354 return do_add_ioctl(cmd, "sit0", &p);
357 default: 355 default:
358 fprintf(stderr, "cannot determine tunnel mode (ipip, gre or sit)\n"); 356 error_msg("cannot determine tunnel mode (ipip, gre or sit)");
359 return -1; 357 return -1;
360 } 358 }
361 return -1; 359 return -1;
@@ -464,7 +462,7 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
464 buf[sizeof(buf) - 1] = 0; 462 buf[sizeof(buf) - 1] = 0;
465 if ((ptr = strchr(buf, ':')) == NULL || 463 if ((ptr = strchr(buf, ':')) == NULL ||
466 (*ptr++ = 0, sscanf(buf, "%s", name) != 1)) { 464 (*ptr++ = 0, sscanf(buf, "%s", name) != 1)) {
467 fprintf(stderr, "Wrong format of /proc/net/dev. Sorry.\n"); 465 error_msg("Wrong format of /proc/net/dev. Sorry.");
468 return -1; 466 return -1;
469 } 467 }
470 if (sscanf(ptr, "%ld%ld%ld%ld%ld%ld%ld%*d%ld%ld%ld%ld%ld%ld%ld", 468 if (sscanf(ptr, "%ld%ld%ld%ld%ld%ld%ld%*d%ld%ld%ld%ld%ld%ld%ld",
@@ -477,7 +475,7 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
477 continue; 475 continue;
478 type = do_ioctl_get_iftype(name); 476 type = do_ioctl_get_iftype(name);
479 if (type == -1) { 477 if (type == -1) {
480 fprintf(stderr, "Failed to get type of [%s]\n", name); 478 error_msg("Failed to get type of [%s]", name);
481 continue; 479 continue;
482 } 480 }
483 if (type != ARPHRD_TUNNEL && type != ARPHRD_IPGRE && type != ARPHRD_SIT) 481 if (type != ARPHRD_TUNNEL && type != ARPHRD_IPGRE && type != ARPHRD_SIT)
@@ -543,6 +541,6 @@ int do_iptunnel(int argc, char **argv)
543 } else 541 } else
544 return do_show(0, NULL); 542 return do_show(0, NULL);
545 543
546 fprintf(stderr, "Command \"%s\" is unknown, try \"ip tunnel help\".\n", *argv); 544 error_msg("Command \"%s\" is unknown, try \"ip tunnel help\".", *argv);
547 exit(-1); 545 exit(-1);
548} 546}