~vcs-imports/busybox/trunk

« back to all changes in this revision

Viewing changes to networking/udhcp/dhcpc.c

  • Committer: Denys Vlasenko
  • Author(s): Roger Knecht
  • Date: 2022-06-30 15:18:12 UTC
  • Revision ID: git-v1:20a4f70ecaad79bb932af09b7317a058872cd867
tree: new applet

Adds the tree program to list directories and files in a tree structure.

function                                             old     new   delta
tree_print                                             -     343    +343
scandir64                                              -     330    +330
scandir                                                -     330    +330
tree_main                                              -      86     +86
.rodata                                           105150  105228     +78
packed_usage                                       34511   34557     +46
alphasort64                                            -      31     +31
alphasort                                              -      31     +31
strcoll                                                -       5      +5
applet_names                                        2801    2806      +5
applet_main                                         1616    1620      +4
applet_suid                                          101     102      +1
applet_install_loc                                   202     203      +1
------------------------------------------------------------------------------
(add/remove: 11/0 grow/shrink: 6/0 up/down: 1291/0)          Total: 1291 bytes

Signed-off-by: Roger Knecht <rknecht@pm.me>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
150
150
        return sprintf(dest, "%s%u.%u.%u.%u", pre, ip[0], ip[1], ip[2], ip[3]);
151
151
}
152
152
 
 
153
/* really simple implementation, just count the bits */
 
154
static int mton(uint32_t mask)
 
155
{
 
156
        int i = 0;
 
157
        mask = ntohl(mask); /* 111110000-like bit pattern */
 
158
        while (mask) {
 
159
                i++;
 
160
                mask <<= 1;
 
161
        }
 
162
        return i;
 
163
}
 
164
 
153
165
#if ENABLE_FEATURE_UDHCPC_SANITIZEOPT
154
166
/* Check if a given name represents a valid DNS name */
155
167
/* See RFC1035, 2.3.1 */
496
508
                                /* Generate extra envvar for DHCP_SUBNET, $mask */
497
509
                                uint32_t subnet;
498
510
                                move_from_unaligned32(subnet, opt_item->data);
499
 
//FIXME: we do not check that subnet has bit pattern 11..10..0
500
 
                                putenvp(xasprintf("mask=%u", bb_popcnt_32(subnet)));
 
511
                                putenvp(xasprintf("mask=%u", mton(subnet)));
501
512
                        }
502
513
                } else {
503
514
                        unsigned ofs;
955
966
        check = packet.udp.check;
956
967
        packet.udp.check = 0;
957
968
        if (check && check != inet_cksum(&packet, bytes)) {
958
 
                log1s("packet with bad UDP checksum, ignoring");
 
969
                log1s("packet with bad UDP checksum received, ignoring");
959
970
                return -2;
960
971
        }
961
972
 skip_udp_sum_check:
962
973
 
963
 
        if (packet.data.cookie != htonl(RFC1048_MAGIC)) {
 
974
        if (packet.data.cookie != htonl(DHCP_MAGIC)) {
964
975
                log1s("packet with bad magic, ignoring");
965
976
                return -2;
966
977
        }
970
981
        udhcp_dump_packet(&packet.data);
971
982
 
972
983
        bytes -= sizeof(packet.ip) + sizeof(packet.udp);
973
 
        memset(dhcp_pkt, 0, sizeof(*dhcp_pkt));
974
984
        memcpy(dhcp_pkt, &packet.data, bytes);
975
985
        return bytes;
976
986
}