]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Optimize code around NULL terminated hostname.
authorRoy Marples <roy@marples.name>
Mon, 26 Jan 2009 12:49:12 +0000 (12:49 +0000)
committerRoy Marples <roy@marples.name>
Mon, 26 Jan 2009 12:49:12 +0000 (12:49 +0000)
dhcp.c

diff --git a/dhcp.c b/dhcp.c
index b157c6f8b53da428ea12bd4852f05b8b6ac727ac..20c73771e9c8e5e9948d89cc8cb4bafc6b22f383 100644 (file)
--- 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;
                }