networking/libiproute/*: code shrink by optimizing numeric conversions
[oweals/busybox.git] / networking / libiproute / ll_proto.c
index b8268732e6f9f046088e0fe403ceea24974b3ff4..a93493538cb947f9b2c8969b49e3f3f4e325bd37 100644 (file)
@@ -115,13 +115,15 @@ int ll_proto_a2n(unsigned short *id, char *buf)
        unsigned i;
        for (i = 0; i < ARRAY_SIZE(llproto_names); i++) {
                 if (strcasecmp(llproto_names[i].name, buf) == 0) {
-                        *id = htons(llproto_names[i].id);
-                        return 0;
+                        i = llproto_names[i].id;
+                        goto good;
                 }
        }
-       if (get_u16(id, buf, 0))
+       i = bb_strtou(buf, NULL, 0);
+       if (errno || i > 0xffff)
                return -1;
-       *id = htons(*id);
+ good:
+       *id = htons(i);
        return 0;
 }