- Update l2ping(8) man page and mention that it is possible to use names

instead of BD_ADDRs

- Convert BD_ADDRs in l2ping(8) output into the human readable names via
  bt_gethostbyaddr(3)

- Introduce and document '-n' - numberic output option

Suggested by: Anil Madhavapeddy <anil at recoil dot org>
This commit is contained in:
emax 2004-08-04 20:43:57 +00:00
parent fb7bd65f3f
commit dc4be55644
2 changed files with 70 additions and 42 deletions

View File

@ -33,27 +33,30 @@
.Nd send L2CAP ECHO_REQUEST to remote devices
.Sh SYNOPSIS
.Nm
.Op Fl fh
.Fl a Ar BD_ADDR
.Op Fl fhn
.Fl a Ar remote
.Op Fl c Ar count
.Op Fl i Ar delay
.Op Fl S Ar BD_ADDR
.Op Fl S Ar source
.Op Fl s Ar size
.Sh DESCRIPTION
The
.Nm
utility uses L2CAP
.Dv ECHO_REQUEST
datagram to elicit an L2CAP
datagram to elicit a L2CAP
.Dv ECHO_RESPONSE
from a remote device.
datagram from a remote device.
.Pp
The options are as follows:
.Bl -tag -width indent
.It Fl a Ar BD_ADDR
Address of remote device to ping.
Example:
.Fl a Li 00:01:02:03:04:05 .
.It Fl a Ar remote
Specify the remote device to ping.
The remote device can be specified by either its BD_ADDR or name.
If name was specified then the
.Nm
utility will attempt to resolve the name via
.Xr bt_gethostbyname 3 .
.It Fl c Ar count
Number of packets to send.
If this option is not specified,
@ -72,18 +75,27 @@ The default is to wait for one second between each packet.
This option is ignored if
.Fl f
has been specified.
.It Fl S Ar BD_ADDR
Send L2CAP
.It Fl n
Numeric output only.
No attempt will be made to lookup symbolic names for host addresses.
.It Fl S Ar source
Specify the local device which should be used to send L2CAP
.Dv ECHO_REQUEST
from local device that has
.Ar BD_ADDR .
Example:
.Fl S Li 00:05:04:03:02:01 .
datagrams.
The local device can be specified by either its BD_ADDR or name.
If name was specified then the
.Nm
utility will attempt to resolve the name via
.Xr bt_gethostbyname 3 .
.It Fl s Ar size
Specify the number of payload bytes to be sent.
The default is the minimum L2CAP MTU minus the size of the L2CAP signalling
command header (44 bytes).
The maximum size is 65531.
The default size is 44 bytes.
It is calculated as minimum L2CAP MTU (48 bytes) minus the size of the L2CAP
signalling command header (4 bytes).
The maximum size is 65531 bytes. Is is calculated as maximum L2CAP MTU
(65535 bytes) minus four bytes of payload reserved for
.Nm
internal use.
Use this option with caution.
Some implementations may not like large sizes and may hang or even crash.
.El
@ -93,6 +105,7 @@ Could check for duplicated, corrupted and lost packets.
.Sh DIAGNOSTICS
.Ex -std
.Sh SEE ALSO
.Xr bluetooth 3 ,
.Xr netgraph 3 ,
.Xr netgraph 4 ,
.Xr ng_l2cap 4 ,

View File

@ -63,7 +63,8 @@ main(int argc, char *argv[])
struct hostent *he = NULL;
uint8_t *echo_data = NULL;
struct sockaddr_l2cap sa;
int32_t n, s, count, wait, flood, echo_size;
int32_t n, s, count, wait, flood, echo_size, numeric;
char *rname = NULL;
/* Set defaults */
memcpy(&src, NG_HCI_BDADDR_ANY, sizeof(src));
@ -84,9 +85,10 @@ main(int argc, char *argv[])
count = -1; /* unimited */
wait = 1; /* sec */
flood = 0;
numeric = 0;
/* Parse command line arguments */
while ((n = getopt(argc, argv, "a:c:fi:n:s:S:h")) != -1) {
while ((n = getopt(argc, argv, "a:c:fi:nS:s:h")) != -1) {
switch (n) {
case 'a':
if (!bt_aton(optarg, &dst)) {
@ -97,15 +99,6 @@ main(int argc, char *argv[])
}
break;
case 'S':
if (!bt_aton(optarg, &src)) {
if ((he = bt_gethostbyname(optarg)) == NULL)
errx(1, "%s: %s", optarg, hstrerror(h_errno));
memcpy(&src, he->h_addr, sizeof(src));
}
break;
case 'c':
count = atoi(optarg);
if (count <= 0)
@ -122,13 +115,24 @@ main(int argc, char *argv[])
usage();
break;
case 'n':
numeric = 1;
break;
case 'S':
if (!bt_aton(optarg, &src)) {
if ((he = bt_gethostbyname(optarg)) == NULL)
errx(1, "%s: %s", optarg, hstrerror(h_errno));
memcpy(&src, he->h_addr, sizeof(src));
}
break;
case 's':
echo_size = atoi(optarg);
if (echo_size < sizeof(int32_t))
if (echo_size < sizeof(int32_t) ||
echo_size > NG_L2CAP_MAX_ECHO_SIZE)
usage();
if (echo_size > NG_L2CAP_MAX_ECHO_SIZE)
echo_size = NG_L2CAP_MAX_ECHO_SIZE;
break;
case 'h':
@ -141,6 +145,15 @@ main(int argc, char *argv[])
if (memcmp(&dst, NG_HCI_BDADDR_ANY, sizeof(dst)) == 0)
usage();
he = bt_gethostbyaddr((const char *)&dst, sizeof(dst), AF_BLUETOOTH);
if (he == NULL || he->h_name == NULL || he->h_name[0] == '\0' || numeric)
asprintf(&rname, "%s", bt_ntoa(&dst, NULL));
else
rname = strdup(he->h_name);
if (rname == NULL)
errx(1, "Failed to create remote hostname");
s = socket(PF_BLUETOOTH, SOCK_RAW, BLUETOOTH_PROTO_L2CAP);
if (s < 0)
err(2, "Could not create socket");
@ -203,7 +216,7 @@ main(int argc, char *argv[])
fprintf(stdout,
"%d bytes from %s seq_no=%d time=%.3f ms result=%#x %s\n",
r.echo_size,
bt_ntoa(&dst, NULL),
rname,
ntohl(*((int32_t *)(r.echo_data))),
tv2msec(&b), r.result,
((fail == 0)? "" : strerror(errno)));
@ -219,6 +232,7 @@ main(int argc, char *argv[])
count --;
}
free(rname);
free(echo_data);
close(s);
@ -259,16 +273,17 @@ static void
usage(void)
{
fprintf(stderr, "Usage: l2ping -a bd_addr " \
"[-S bd_addr -c count -i wait -s size -h]\n");
"[-S bd_addr -c count -i wait -n -s size -h]\n");
fprintf(stderr, "Where:\n");
fprintf(stderr, "\t-S bd_addr - Source BD_ADDR\n");
fprintf(stderr, "\t-a bd_addr - Remote BD_ADDR to ping\n");
fprintf(stderr, "\t-c count - Number of packets to send\n");
fprintf(stderr, "\t-f - No delay (soft of flood)\n");
fprintf(stderr, "\t-i wait - Delay between packets (sec)\n");
fprintf(stderr, "\t-s size - Packet size (bytes), " \
fprintf(stderr, " -a remote Specify remote device to ping\n");
fprintf(stderr, " -c count Number of packets to send\n");
fprintf(stderr, " -f No delay (soft of flood)\n");
fprintf(stderr, " -h Display this message\n");
fprintf(stderr, " -i wait Delay between packets (sec)\n");
fprintf(stderr, " -n Numeric output only\n");
fprintf(stderr, " -S source Specify source device\n");
fprintf(stderr, " -s size Packet size (bytes), " \
"between %zd and %zd\n", sizeof(int32_t), NG_L2CAP_MAX_ECHO_SIZE);
fprintf(stderr, "\t-h - Display this message\n");
exit(255);
} /* usage */