24 */
25
26 #include <sys/types.h>
27 #include <string.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <errno.h>
31 #include <stdarg.h>
32 #include <limits.h>
33 #include <ctype.h>
34 #include <libgen.h>
35 #include <sys/isa_defs.h>
36 #include <sys/socket.h>
37 #include <net/if_arp.h>
38 #include <netinet/in.h>
39 #include <arpa/inet.h>
40 #include <sys/sysmacros.h>
41 #include <libinetutil.h>
42 #include <libdlpi.h>
43 #include <netinet/dhcp6.h>
44
45 #include "dhcp_symbol.h"
46 #include "dhcp_inittab.h"
47
48 static void inittab_msg(const char *, ...);
49 static uchar_t category_to_code(const char *);
50 static boolean_t encode_number(uint8_t, uint8_t, boolean_t, uint8_t,
51 const char *, uint8_t *, int *);
52 static boolean_t decode_number(uint8_t, uint8_t, boolean_t, uint8_t,
53 const uint8_t *, char *, int *);
54 static dhcp_symbol_t *inittab_lookup(uchar_t, char, const char *, int32_t,
55 size_t *);
56 static dsym_category_t itabcode_to_dsymcode(uchar_t);
57 static boolean_t parse_entry(char *, char **);
58
59 /*
60 * forward declaration of our internal inittab_table[]. too bulky to put
61 * up front -- check the end of this file for its definition.
62 *
63 * Note: we have only an IPv4 version here. The inittab_verify() function is
490 if (isdigit(chr)) {
491 val = (val << 4) + chr - '0';
492 } else if (isxdigit(chr)) {
493 val = (val << 4) + chr -
494 (isupper(chr) ? 'A' : 'a') + 10;
495 } else if (isspace(chr) && dig == 0) {
496 continue;
497 } else if (chr == ':' || chr == '-' ||
498 isspace(chr)) {
499 dig = 1;
500 } else {
501 goto failed;
502 }
503 if (++dig == 2) {
504 *outbuf++ = val;
505 maclen++;
506 dig = val = 0;
507 }
508 }
509 } else {
510 if (dlpi_info(dh, &dlinfo, 0) != DLPI_SUCCESS) {
511 dlpi_close(dh);
512 goto failed;
513 }
514 maclen = dlinfo.di_physaddrlen;
515 (void) memcpy(outbuf, dlinfo.di_physaddr, maclen);
516 dlpi_close(dh);
517 if (hwtype == -1)
518 hwtype = dlpi_arptype(dlinfo.di_mactype);
519 }
520 }
521 if (hwtype == -1)
522 goto failed;
523 *hwret = htons(hwtype);
524 return (maclen);
525
526 failed:
527 *ierrnop = ITAB_BAD_NUMBER;
528 return (-1);
529 }
530
|
24 */
25
26 #include <sys/types.h>
27 #include <string.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <errno.h>
31 #include <stdarg.h>
32 #include <limits.h>
33 #include <ctype.h>
34 #include <libgen.h>
35 #include <sys/isa_defs.h>
36 #include <sys/socket.h>
37 #include <net/if_arp.h>
38 #include <netinet/in.h>
39 #include <arpa/inet.h>
40 #include <sys/sysmacros.h>
41 #include <libinetutil.h>
42 #include <libdlpi.h>
43 #include <netinet/dhcp6.h>
44 #include <sys/ethernet.h>
45
46 #include "dhcp_symbol.h"
47 #include "dhcp_inittab.h"
48
49 static void inittab_msg(const char *, ...);
50 static uchar_t category_to_code(const char *);
51 static boolean_t encode_number(uint8_t, uint8_t, boolean_t, uint8_t,
52 const char *, uint8_t *, int *);
53 static boolean_t decode_number(uint8_t, uint8_t, boolean_t, uint8_t,
54 const uint8_t *, char *, int *);
55 static dhcp_symbol_t *inittab_lookup(uchar_t, char, const char *, int32_t,
56 size_t *);
57 static dsym_category_t itabcode_to_dsymcode(uchar_t);
58 static boolean_t parse_entry(char *, char **);
59
60 /*
61 * forward declaration of our internal inittab_table[]. too bulky to put
62 * up front -- check the end of this file for its definition.
63 *
64 * Note: we have only an IPv4 version here. The inittab_verify() function is
491 if (isdigit(chr)) {
492 val = (val << 4) + chr - '0';
493 } else if (isxdigit(chr)) {
494 val = (val << 4) + chr -
495 (isupper(chr) ? 'A' : 'a') + 10;
496 } else if (isspace(chr) && dig == 0) {
497 continue;
498 } else if (chr == ':' || chr == '-' ||
499 isspace(chr)) {
500 dig = 1;
501 } else {
502 goto failed;
503 }
504 if (++dig == 2) {
505 *outbuf++ = val;
506 maclen++;
507 dig = val = 0;
508 }
509 }
510 } else {
511 if (dlpi_bind(dh, ETHERTYPE_IPV6, NULL) !=
512 DLPI_SUCCESS || dlpi_info(dh, &dlinfo, 0) !=
513 DLPI_SUCCESS) {
514 dlpi_close(dh);
515 goto failed;
516 }
517 maclen = dlinfo.di_physaddrlen;
518 (void) memcpy(outbuf, dlinfo.di_physaddr, maclen);
519 dlpi_close(dh);
520 if (hwtype == -1)
521 hwtype = dlpi_arptype(dlinfo.di_mactype);
522 }
523 }
524 if (hwtype == -1)
525 goto failed;
526 *hwret = htons(hwtype);
527 return (maclen);
528
529 failed:
530 *ierrnop = ITAB_BAD_NUMBER;
531 return (-1);
532 }
533
|