diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-04-04 15:29:32 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-04-04 15:29:32 +0200 |
commit | 4836331924b5eb7f74e000d50c99bc12d513f8c7 (patch) | |
tree | 96c25b9daf69ba688350874e9b51bfc6758237fe /networking/interface.c | |
parent | c03602baa483ed07230c88075121e0f56a4c0428 (diff) | |
download | busybox-w32-4836331924b5eb7f74e000d50c99bc12d513f8c7.tar.gz busybox-w32-4836331924b5eb7f74e000d50c99bc12d513f8c7.tar.bz2 busybox-w32-4836331924b5eb7f74e000d50c99bc12d513f8c7.zip |
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.c | 52 |
1 files changed, 5 insertions, 47 deletions
diff --git a/networking/interface.c b/networking/interface.c index b59a61de4..a59f310a6 100644 --- a/networking/interface.c +++ b/networking/interface.c | |||
@@ -30,7 +30,6 @@ | |||
30 | * 20001008 - Bernd Eckenfels, Patch from RH for setting mtu | 30 | * 20001008 - Bernd Eckenfels, Patch from RH for setting mtu |
31 | * (default AF was wrong) | 31 | * (default AF was wrong) |
32 | */ | 32 | */ |
33 | |||
34 | #include <net/if.h> | 33 | #include <net/if.h> |
35 | #include <net/if_arp.h> | 34 | #include <net/if_arp.h> |
36 | #if (defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined(_NEWLIB_VERSION) | 35 | #if (defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined(_NEWLIB_VERSION) |
@@ -1215,53 +1214,12 @@ static int if_print(char *ifname) | |||
1215 | /* Input an Infiniband address and convert to binary. */ | 1214 | /* Input an Infiniband address and convert to binary. */ |
1216 | int FAST_FUNC in_ib(const char *bufp, struct sockaddr *sap) | 1215 | int FAST_FUNC in_ib(const char *bufp, struct sockaddr *sap) |
1217 | { | 1216 | { |
1218 | unsigned char *ptr; | ||
1219 | char c; | ||
1220 | const char *orig; | ||
1221 | int i; | ||
1222 | unsigned val; | ||
1223 | |||
1224 | sap->sa_family = ib_hwtype.type; | 1217 | sap->sa_family = ib_hwtype.type; |
1225 | ptr = (unsigned char *) sap->sa_data; | 1218 | //TODO: error check? |
1226 | 1219 | hex2bin((char*)sap->sa_data, bufp, INFINIBAND_ALEN); | |
1227 | i = 0; | 1220 | # ifdef HWIB_DEBUG |
1228 | orig = bufp; | 1221 | fprintf(stderr, "in_ib(%s): %s\n", bufp, UNSPEC_print(sap->sa_data)); |
1229 | while ((*bufp != '\0') && (i < INFINIBAND_ALEN)) { | 1222 | # endif |
1230 | val = 0; | ||
1231 | c = *bufp++; | ||
1232 | if (isdigit(c)) | ||
1233 | val = c - '0'; | ||
1234 | else if ((c|0x20) >= 'a' && (c|0x20) <= 'f') | ||
1235 | val = (c|0x20) - ('a' - 10); | ||
1236 | else { | ||
1237 | errno = EINVAL; | ||
1238 | return -1; | ||
1239 | } | ||
1240 | val <<= 4; | ||
1241 | c = *bufp; | ||
1242 | if (isdigit(c)) | ||
1243 | val |= c - '0'; | ||
1244 | else if ((c|0x20) >= 'a' && (c|0x20) <= 'f') | ||
1245 | val |= (c|0x20) - ('a' - 10); | ||
1246 | else if (c == ':' || c == '\0') | ||
1247 | val >>= 4; | ||
1248 | else { | ||
1249 | errno = EINVAL; | ||
1250 | return -1; | ||
1251 | } | ||
1252 | if (c != '\0') | ||
1253 | bufp++; | ||
1254 | *ptr++ = (unsigned char) (val & 0377); | ||
1255 | i++; | ||
1256 | |||
1257 | /* We might get a semicolon here - not required. */ | ||
1258 | if (*bufp == ':') { | ||
1259 | bufp++; | ||
1260 | } | ||
1261 | } | ||
1262 | #ifdef DEBUG | ||
1263 | fprintf(stderr, "in_ib(%s): %s\n", orig, UNSPEC_print(sap->sa_data)); | ||
1264 | #endif | ||
1265 | return 0; | 1223 | return 0; |
1266 | } | 1224 | } |
1267 | #endif | 1225 | #endif |