summaryrefslogtreecommitdiff
path: root/networking/interface.c
diff options
context:
space:
mode:
authorDenys Vlasenko2010-04-04 15:29:32 +0200
committerDenys Vlasenko2010-04-04 15:29:32 +0200
commit4836331924b5eb7f74e000d50c99bc12d513f8c7 (patch)
tree96c25b9daf69ba688350874e9b51bfc6758237fe /networking/interface.c
parentc03602baa483ed07230c88075121e0f56a4c0428 (diff)
downloadbusybox-4836331924b5eb7f74e000d50c99bc12d513f8c7.zip
busybox-4836331924b5eb7f74e000d50c99bc12d513f8c7.tar.gz
libbb: factor out hex2bin() for infiniband address parser
function old new delta hex2bin - 149 +149 in_ib 172 27 -145 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/interface.c')
-rw-r--r--networking/interface.c52
1 files changed, 5 insertions, 47 deletions
diff --git a/networking/interface.c b/networking/interface.c
index b59a61d..a59f310 100644
--- a/networking/interface.c
+++ b/networking/interface.c
@@ -30,7 +30,6 @@
* 20001008 - Bernd Eckenfels, Patch from RH for setting mtu
* (default AF was wrong)
*/
-
#include <net/if.h>
#include <net/if_arp.h>
#if (defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined(_NEWLIB_VERSION)
@@ -1215,53 +1214,12 @@ static int if_print(char *ifname)
/* Input an Infiniband address and convert to binary. */
int FAST_FUNC in_ib(const char *bufp, struct sockaddr *sap)
{
- unsigned char *ptr;
- char c;
- const char *orig;
- int i;
- unsigned val;
-
sap->sa_family = ib_hwtype.type;
- ptr = (unsigned char *) sap->sa_data;
-
- i = 0;
- orig = bufp;
- while ((*bufp != '\0') && (i < INFINIBAND_ALEN)) {
- val = 0;
- c = *bufp++;
- if (isdigit(c))
- val = c - '0';
- else if ((c|0x20) >= 'a' && (c|0x20) <= 'f')
- val = (c|0x20) - ('a' - 10);
- else {
- errno = EINVAL;
- return -1;
- }
- val <<= 4;
- c = *bufp;
- if (isdigit(c))
- val |= c - '0';
- else if ((c|0x20) >= 'a' && (c|0x20) <= 'f')
- val |= (c|0x20) - ('a' - 10);
- else if (c == ':' || c == '\0')
- val >>= 4;
- else {
- errno = EINVAL;
- return -1;
- }
- if (c != '\0')
- bufp++;
- *ptr++ = (unsigned char) (val & 0377);
- i++;
-
- /* We might get a semicolon here - not required. */
- if (*bufp == ':') {
- bufp++;
- }
- }
-#ifdef DEBUG
- fprintf(stderr, "in_ib(%s): %s\n", orig, UNSPEC_print(sap->sa_data));
-#endif
+//TODO: error check?
+ hex2bin((char*)sap->sa_data, bufp, INFINIBAND_ALEN);
+# ifdef HWIB_DEBUG
+ fprintf(stderr, "in_ib(%s): %s\n", bufp, UNSPEC_print(sap->sa_data));
+# endif
return 0;
}
#endif