Print this page
5007142 Add ntohll and htonll to sys/byteorder.h
6717509 Need to use bswap/bswapq for byte swap of 64-bit integer on x32/x64
PSARC 2008/474

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libdhcputil/common/dhcp_inittab.c
          +++ new/usr/src/lib/libdhcputil/common/dhcp_inittab.c
↓ open down ↓ 11 lines elided ↑ open up ↑
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22      - * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
       22 + * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
  25   25  
  26      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  27      -
  28   26  #include <sys/types.h>
  29   27  #include <string.h>
  30   28  #include <stdlib.h>
  31   29  #include <stdio.h>
  32   30  #include <errno.h>
  33   31  #include <stdarg.h>
  34   32  #include <limits.h>
  35   33  #include <ctype.h>
  36   34  #include <libgen.h>
  37   35  #include <sys/isa_defs.h>
↓ open down ↓ 2 lines elided ↑ open up ↑
  40   38  #include <netinet/in.h>
  41   39  #include <arpa/inet.h>
  42   40  #include <sys/sysmacros.h>
  43   41  #include <libinetutil.h>
  44   42  #include <libdlpi.h>
  45   43  #include <netinet/dhcp6.h>
  46   44  
  47   45  #include "dhcp_symbol.h"
  48   46  #include "dhcp_inittab.h"
  49   47  
  50      -static uint64_t         dhcp_htonll(uint64_t);
  51      -static uint64_t         dhcp_ntohll(uint64_t);
  52   48  static void             inittab_msg(const char *, ...);
  53   49  static uchar_t          category_to_code(const char *);
  54   50  static boolean_t        encode_number(uint8_t, uint8_t, boolean_t, uint8_t,
  55   51                              const char *, uint8_t *, int *);
  56   52  static boolean_t        decode_number(uint8_t, uint8_t, boolean_t, uint8_t,
  57   53                              const uint8_t *, char *, int *);
  58   54  static dhcp_symbol_t    *inittab_lookup(uchar_t, char, const char *, int32_t,
  59   55                              size_t *);
  60   56  static dsym_category_t  itabcode_to_dsymcode(uchar_t);
  61   57  static boolean_t        parse_entry(char *, char **);
↓ open down ↓ 1409 lines elided ↑ open up ↑
1471 1467  
1472 1468                  case 4:
1473 1469                          (void) memcpy(&uint32, from, 4);
1474 1470                          to += sprintf(to, is_signed ? "%ld" : "%lu",
1475 1471                              ntohl(uint32));
1476 1472                          break;
1477 1473  
1478 1474                  case 8:
1479 1475                          (void) memcpy(&uint64, from, 8);
1480 1476                          to += sprintf(to, is_signed ? "%lld" : "%llu",
1481      -                            dhcp_ntohll(uint64));
     1477 +                            ntohll(uint64));
1482 1478                          break;
1483 1479  
1484 1480                  default:
1485 1481                          *ierrnop = ITAB_BAD_NUMBER;
1486 1482                          inittab_msg("decode_number: unknown integer size `%d'",
1487 1483                              size);
1488 1484                          return (B_FALSE);
1489 1485                  }
1490 1486                  if (n_entries > 0)
1491 1487                          *to++ = ' ';
↓ open down ↓ 75 lines elided ↑ open up ↑
1567 1563  
1568 1564                  case 4:
1569 1565                          uint32 = htonl(strtoul(from, &endptr, 0));
1570 1566                          if (errno != 0 || from == endptr) {
1571 1567                                  goto error;
1572 1568                          }
1573 1569                          (void) memcpy(to, &uint32, 4);
1574 1570                          break;
1575 1571  
1576 1572                  case 8:
1577      -                        uint64 = dhcp_htonll(strtoull(from, &endptr, 0));
     1573 +                        uint64 = htonll(strtoull(from, &endptr, 0));
1578 1574                          if (errno != 0 || from == endptr) {
1579 1575                                  goto error;
1580 1576                          }
1581 1577                          (void) memcpy(to, &uint64, 8);
1582 1578                          break;
1583 1579  
1584 1580                  default:
1585 1581                          inittab_msg("encode_number: unsupported integer "
1586 1582                              "size `%d'", size);
1587 1583                          return (B_FALSE);
↓ open down ↓ 100 lines elided ↑ open up ↑
1688 1684          unsigned int    i;
1689 1685  
1690 1686          for (i = 0; i < ITAB_CAT_COUNT; i++)
1691 1687                  if (strcasecmp(category_map[i].cme_name, category) == 0)
1692 1688                          return (category_map[i].cme_itabcode);
1693 1689  
1694 1690          return (0);
1695 1691  }
1696 1692  
1697 1693  /*
1698      - * dhcp_htonll(): converts a 64-bit number from host to network byte order
1699      - *
1700      - *   input: uint64_t: the number to convert
1701      - *  output: uint64_t: its value in network byte order
1702      - */
1703      -
1704      -static uint64_t
1705      -dhcp_htonll(uint64_t uint64_hbo)
1706      -{
1707      -        return (dhcp_ntohll(uint64_hbo));
1708      -}
1709      -
1710      -/*
1711      - * dhcp_ntohll(): converts a 64-bit number from network to host byte order
1712      - *
1713      - *   input: uint64_t: the number to convert
1714      - *  output: uint64_t: its value in host byte order
1715      - */
1716      -
1717      -static uint64_t
1718      -dhcp_ntohll(uint64_t uint64_nbo)
1719      -{
1720      -#ifdef  _LITTLE_ENDIAN
1721      -        return ((uint64_t)ntohl(uint64_nbo & 0xffffffff) << 32 |
1722      -            ntohl(uint64_nbo >> 32));
1723      -#else
1724      -        return (uint64_nbo);
1725      -#endif
1726      -}
1727      -
1728      -/*
1729 1694   * our internal table of DHCP option values, used by inittab_verify()
1730 1695   */
1731 1696  static dhcp_symbol_t inittab_table[] =
1732 1697  {
1733 1698  { DSYM_INTERNAL,        1024,   "Hostname",     DSYM_BOOL,      0,      0 },
1734 1699  { DSYM_INTERNAL,        1025,   "LeaseNeg",     DSYM_BOOL,      0,      0 },
1735 1700  { DSYM_INTERNAL,        1026,   "EchoVC",       DSYM_BOOL,      0,      0 },
1736 1701  { DSYM_INTERNAL,        1027,   "BootPath",     DSYM_ASCII,     1,      128 },
1737 1702  { DSYM_FIELD,           0,      "Opcode",       DSYM_UNUMBER8,  1,      1 },
1738 1703  { DSYM_FIELD,           1,      "Htype",        DSYM_UNUMBER8,  1,      1 },
1739 1704  { DSYM_FIELD,           2,      "HLen",         DSYM_UNUMBER8,  1,      1 },
1740 1705  { DSYM_FIELD,           3,      "Hops",         DSYM_UNUMBER8,  1,      1 },
1741 1706  { DSYM_FIELD,           4,      "Xid",          DSYM_UNUMBER32, 1,      1 },
1742 1707  { DSYM_FIELD,           8,      "Secs",         DSYM_UNUMBER16, 1,      1 },
1743 1708  { DSYM_FIELD,           10,     "Flags",        DSYM_OCTET,     1,      2 },
1744 1709  { DSYM_FIELD,           12,     "Ciaddr",       DSYM_IP,        1,      1 },
1745 1710  { DSYM_FIELD,           16,     "Yiaddr",       DSYM_IP,        1,      1 },
1746 1711  { DSYM_FIELD,           20,     "BootSrvA",     DSYM_IP,        1,      1 },
1747 1712  { DSYM_FIELD,           24,     "Giaddr",       DSYM_IP,        1,      1 },
1748      -{ DSYM_FIELD,           28,     "Chaddr",       DSYM_OCTET,     1,      16 },
     1713 +{ DSYM_FIELD,           28,     "Chaddr",       DSYM_OCTET,     1,      16 },
1749 1714  { DSYM_FIELD,           44,     "BootSrvN",     DSYM_ASCII,     1,      64 },
1750 1715  { DSYM_FIELD,           108,    "BootFile",     DSYM_ASCII,     1,      128 },
1751 1716  { DSYM_FIELD,           236,    "Magic",        DSYM_OCTET,     1,      4 },
1752 1717  { DSYM_FIELD,           240,    "Options",      DSYM_OCTET,     1,      60 },
1753 1718  { DSYM_STANDARD,        1,      "Subnet",       DSYM_IP,        1,      1 },
1754 1719  { DSYM_STANDARD,        2,      "UTCoffst",     DSYM_SNUMBER32, 1,      1 },
1755 1720  { DSYM_STANDARD,        3,      "Router",       DSYM_IP,        1,      0 },
1756 1721  { DSYM_STANDARD,        4,      "Timeserv",     DSYM_IP,        1,      0 },
1757 1722  { DSYM_STANDARD,        5,      "IEN116ns",     DSYM_IP,        1,      0 },
1758 1723  { DSYM_STANDARD,        6,      "DNSserv",      DSYM_IP,        1,      0 },
↓ open down ↓ 77 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX