aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Davidson <colrdavidson@gmail.com>2019-02-25 00:21:55 -0500
committerRob Landley <rob@landley.net>2019-02-25 11:28:53 -0600
commit8e82fca1cd7e2a39a4e8bdbfadc73b95178be1d9 (patch)
tree980f11762fe5348d0e285db11fd0879d02bcd5fd
parent2d17d2762b0b05295917b9f8e451e5f7783a2da1 (diff)
downloadtoybox-8e82fca1cd7e2a39a4e8bdbfadc73b95178be1d9.tar.gz
arp: inline get_hw_add and minor sscanf error handling cleanup
-rw-r--r--toys/pending/arp.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/toys/pending/arp.c b/toys/pending/arp.c
index 6b57c3ca..7e7b8668 100644
--- a/toys/pending/arp.c
+++ b/toys/pending/arp.c
@@ -84,25 +84,6 @@ static int get_index(struct type arr[], char *name)
return arr[i].val;
}
-
-void get_hw_add(char *hw_addr, char *ptr)
-{
- char *p = ptr, *hw = hw_addr;
-
- while (*hw_addr && (p-ptr) < 6) {
- int val, len = 0;
-
- if (*hw_addr == ':') hw_addr++;
- sscanf(hw_addr, "%2x%n", &val, &len);
- if (!len || len > 2) break;
- hw_addr += len;
- *p++ = val;
- }
-
- if ((p-ptr) != 6 || *hw_addr)
- error_exit("bad hw addr '%s'", hw);
-}
-
static void resolve_host(char *host, struct sockaddr *sa)
{
struct addrinfo hints, *res = NULL;
@@ -161,8 +142,22 @@ static int set_entry(void)
if (!toys.optargs[1]) error_exit("bad syntax");
- if (!(toys.optflags & FLAG_D)) get_hw_add(toys.optargs[1], (char*)&req.arp_ha.sa_data);
- else {
+ if (!(toys.optflags & FLAG_D)) {
+ char *ptr = toys.optargs[1];
+ char *p = ptr, *hw_addr = req.arp_ha.sa_data;
+
+ while (*hw_addr && (p-ptr) < 6) {
+ int val, len;
+
+ if (*hw_addr == ':') hw_addr++;
+ if (!sscanf(hw_addr, "%2x%n", &val, &len)) break;
+ hw_addr += len;
+ *p++ = val;
+ }
+
+ if ((p-ptr) != 6 || *hw_addr)
+ error_exit("bad hw addr '%s'", req.arp_ha.sa_data);
+ } else {
struct ifreq ifre;
xstrncpy(ifre.ifr_name, toys.optargs[1], IFNAMSIZ);