summaryrefslogtreecommitdiffstats
path: root/dhcp.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2009-01-26 12:49:12 +0000
committerRoy Marples <roy@marples.name>2009-01-26 12:49:12 +0000
commitcb69faa64089c86fa4d3bb8872d5d319b20ccc69 (patch)
tree0803077243be8977e75688367ac97dfad4d7c91a /dhcp.c
parentee07bdd8336cdd2e23b18ff865e481f03964ec0b (diff)
downloaddhcpcd-cb69faa64089c86fa4d3bb8872d5d319b20ccc69.tar.xz
Optimize code around NULL terminated hostname.
Diffstat (limited to 'dhcp.c')
-rw-r--r--dhcp.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/dhcp.c b/dhcp.c
index b157c6f8..20c73771 100644
--- a/dhcp.c
+++ b/dhcp.c
@@ -719,28 +719,27 @@ get_option_routes(const struct dhcp_message *dhcp)
}
static size_t
-encode_rfc1035(const char *src, uint8_t *dst, size_t len)
+encode_rfc1035(const char *src, uint8_t *dst)
{
- const char *c = src;
uint8_t *p = dst;
uint8_t *lp = p++;
- if (len == 0)
+ if (*src == '\0')
return 0;
- while (c < src + len) {
- if (*c == '\0')
+ while (*src) {
+ if (*src == '\0')
break;
- if (*c == '.') {
+ if (*src == '.') {
/* Skip the trailing . */
- if (c == src + len - 1)
+ if (src[1] == '\0')
break;
*lp = p - lp - 1;
if (*lp == '\0')
return p - dst;
lp = p++;
} else
- *p++ = (uint8_t) *c;
- c++;
+ *p++ = (uint8_t)*src;
+ src++;
}
*lp = p - lp - 1;
*p++ = '\0';
@@ -897,16 +896,13 @@ make_message(struct dhcp_message **message,
if (ifo->hostname[0]) {
*p++ = DHO_HOSTNAME;
hp = strchr(ifo->hostname, '.');
- if (hp) {
- *p++ = hp - ifo->hostname;
- memcpy(p, ifo->hostname, hp - ifo->hostname);
- p += hp - ifo->hostname;
- } else {
+ if (hp)
+ len = hp - ifo->hostname;
+ else
len = strlen(ifo->hostname);
- *p++ = len;
- memcpy(p, ifo->hostname, len);
- p += len;
- }
+ *p++ = len;
+ memcpy(p, ifo->hostname, len);
+ p += len;
}
if (ifo->fqdn != FQDN_DISABLE) {
/* IETF DHC-FQDN option (81), RFC4702 */
@@ -926,8 +922,7 @@ make_message(struct dhcp_message **message,
*p++ = (ifo->fqdn & 0x09) | 0x04;
*p++ = 0; /* from server for PTR RR */
*p++ = 0; /* from server for A RR if S=1 */
- ul = encode_rfc1035(ifo->hostname, p,
- strlen(ifo->hostname));
+ ul = encode_rfc1035(ifo->hostname, p);
*lp += ul;
p += ul;
}