2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright (c) 2018, Joyent, Inc.
17 * Send a raw Ethernet frame once a second to a specified MAC address.
38 static uint_t dlsend_sap
= DLSEND_SAP
;
39 static const char *dlsend_msg
= DLSEND_MSG
;
40 static const char *dlsend_prog
;
43 dlsend_usage(const char *fmt
, ...)
48 (void) fprintf(stderr
, "%s: ", dlsend_prog
);
50 (void) vfprintf(stderr
, fmt
, ap
);
54 (void) fprintf(stderr
, "Usage: %s [-s sap] device target-mac\n"
55 "\t-s sap\tspecify SAP to send on\n",
60 main(int argc
, char *argv
[])
66 char host
[MAXHOSTNAMELEN
];
71 dlsend_prog
= basename(argv
[0]);
73 while ((c
= getopt(argc
, argv
, ":s:")) != -1) {
77 sap
= strtoul(optarg
, &eptr
, 10);
78 if (errno
!= 0 || sap
== 0 || sap
>= UINT16_MAX
||
80 dlsend_usage("Invalid value for sap (-s): %s\n",
87 dlsend_usage("Option -%c requires an operand\n",
91 dlsend_usage("Unknown option: -%c\n", optopt
);
100 dlsend_usage("missing required operands\n");
104 if ((mac
= _link_aton(argv
[1], &maclen
)) == NULL
) {
105 warnx("failed to convert target address %s\n", argv
[1]);
109 if (gethostname(host
, sizeof (host
)) != 0) {
110 warnx("failed to obtain the system hostname: %s\n",
112 (void) strlcpy(host
, "<unknown host>", sizeof (host
));
115 if ((ret
= dlpi_open(argv
[0], &dh
, 0)) != DLPI_SUCCESS
) {
116 warnx("failed to open %s: %s\n", argv
[0],
121 if ((ret
= dlpi_bind(dh
, dlsend_sap
, &bind_sap
)) != DLPI_SUCCESS
) {
122 warnx("failed to bind to sap 0x%x: %s\n", dlsend_sap
,
127 if (bind_sap
!= dlsend_sap
) {
128 warnx("failed to bind to requested sap 0x%x, bound to "
129 "0x%x\n", dlsend_sap
, bind_sap
);
138 bzero(&msg
, sizeof (msg
));
139 msg
.dm_count
= htobe64(count
);
140 (void) strlcpy(msg
.dm_host
, host
, sizeof (msg
.dm_host
));
141 (void) strlcpy(msg
.dm_mesg
, dlsend_msg
, sizeof (msg
.dm_mesg
));
142 ret
= dlpi_send(dh
, mac
, maclen
, &msg
, sizeof (msg
), NULL
);
143 if (ret
!= DLPI_SUCCESS
) {
144 warnx("failed to send message: %s\n",
152 /* LINTED: E_STMT_NOT_REACHED */