aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-01-07 15:23:18 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2019-01-07 15:23:18 +0100
commitb80bdeba0248e2742cf801e7429d5d7aad69d26d (patch)
tree6d46265d1fbd15a4fddabe5ef33ade96ba15ec06 /networking/udhcp
parentedca770d11edcc5b5548a62c068b2e75f1ccb54a (diff)
downloadbusybox-w32-b80bdeba0248e2742cf801e7429d5d7aad69d26d.tar.gz
busybox-w32-b80bdeba0248e2742cf801e7429d5d7aad69d26d.tar.bz2
busybox-w32-b80bdeba0248e2742cf801e7429d5d7aad69d26d.zip
udhcp: code shrink
function old new delta attach_option 406 349 -57 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp')
-rw-r--r--networking/udhcp/common.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c
index 41b05b855..4c2221b77 100644
--- a/networking/udhcp/common.c
+++ b/networking/udhcp/common.c
@@ -422,6 +422,7 @@ static NOINLINE void attach_option(
422 if (errno) 422 if (errno)
423 bb_error_msg_and_die("malformed hex string '%s'", buffer); 423 bb_error_msg_and_die("malformed hex string '%s'", buffer);
424 length = end - allocated; 424 length = end - allocated;
425 buffer = allocated;
425 } 426 }
426#if ENABLE_FEATURE_UDHCP_RFC3397 427#if ENABLE_FEATURE_UDHCP_RFC3397
427 if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) { 428 if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) {
@@ -441,15 +442,14 @@ static NOINLINE void attach_option(
441 new->data = xmalloc(length + OPT_DATA); 442 new->data = xmalloc(length + OPT_DATA);
442 new->data[OPT_CODE] = optflag->code; 443 new->data[OPT_CODE] = optflag->code;
443 new->data[OPT_LEN] = length; 444 new->data[OPT_LEN] = length;
444 memcpy(new->data + OPT_DATA, (allocated ? allocated : buffer), 445 memcpy(new->data + OPT_DATA, buffer, length);
445 length);
446 } else { 446 } else {
447 new->data = xmalloc(length + D6_OPT_DATA); 447 new->data = xmalloc(length + D6_OPT_DATA);
448 new->data[D6_OPT_CODE] = optflag->code >> 8; 448 new->data[D6_OPT_CODE] = optflag->code >> 8;
449 new->data[D6_OPT_CODE + 1] = optflag->code & 0xff; 449 new->data[D6_OPT_CODE + 1] = optflag->code & 0xff;
450 new->data[D6_OPT_LEN] = length >> 8; 450 new->data[D6_OPT_LEN] = length >> 8;
451 new->data[D6_OPT_LEN + 1] = length & 0xff; 451 new->data[D6_OPT_LEN + 1] = length & 0xff;
452 memcpy(new->data + D6_OPT_DATA, (allocated ? allocated : buffer), 452 memcpy(new->data + D6_OPT_DATA, buffer,
453 length); 453 length);
454 } 454 }
455 455
@@ -472,6 +472,8 @@ static NOINLINE void attach_option(
472 /* actually 255 is ok too, but adding a space can overlow it */ 472 /* actually 255 is ok too, but adding a space can overlow it */
473 473
474 existing->data = xrealloc(existing->data, OPT_DATA + 1 + old_len + length); 474 existing->data = xrealloc(existing->data, OPT_DATA + 1 + old_len + length);
475// So far dhcp_optflags[] has no OPTION_STRING[_HOST] | OPTION_LIST items
476#if 0
475 if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING 477 if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING
476 || (optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING_HOST 478 || (optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING_HOST
477 ) { 479 ) {
@@ -479,7 +481,9 @@ static NOINLINE void attach_option(
479 existing->data[OPT_DATA + old_len] = ' '; 481 existing->data[OPT_DATA + old_len] = ' ';
480 old_len++; 482 old_len++;
481 } 483 }
482 memcpy(existing->data + OPT_DATA + old_len, (allocated ? allocated : buffer), length); 484#endif
485
486 memcpy(existing->data + OPT_DATA + old_len, buffer, length);
483 existing->data[OPT_LEN] = old_len + length; 487 existing->data[OPT_LEN] = old_len + length;
484 } /* else, ignore the data, we could put this in a second option in the future */ 488 } /* else, ignore the data, we could put this in a second option in the future */
485 } /* else, ignore the new data */ 489 } /* else, ignore the new data */
@@ -553,7 +557,7 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg,
553 if (retval) 557 if (retval)
554 retval = udhcp_str2nip(val, buffer + 4); 558 retval = udhcp_str2nip(val, buffer + 4);
555 break; 559 break;
556case_OPTION_STRING: 560 case_OPTION_STRING:
557 case OPTION_STRING: 561 case OPTION_STRING:
558 case OPTION_STRING_HOST: 562 case OPTION_STRING_HOST:
559#if ENABLE_FEATURE_UDHCP_RFC3397 563#if ENABLE_FEATURE_UDHCP_RFC3397