Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added simple parsing of UTF-8 machine names (-u commandline option), …

…thanks to Yuriy M. Kaminskiy
  • Loading branch information...
commit 939327bfe3b0655a5b83835acc5cd145131ea0ae 1 parent 479ddd1
@zed-0xff authored
Showing with 61 additions and 4 deletions.
  1. +47 −0 lltd.c
  2. +3 −1 lltdscan.8
  3. +11 −3 lltdscan.c
View
47 lltd.c
@@ -86,6 +86,53 @@ u_char* lltd_extract_name(const u_char*p){
return NULL;
}
+u_char* lltd_extract_unicode_name(const u_char*p){
+ u_char l;
+ static u_char namebuf[0x40];
+
+ while(*p){
+ l = p[1];
+ if( *p == 0x0F ){
+ int namelen = l/2;
+ p += 2;
+ u_char *pbuf;
+ /* convert ucs-2le to utf-8 */
+ /* FIXME: maybe, this is utf-16le, not ucs-2le? */
+ for(pbuf=namebuf; namelen>0; namelen--){
+ unsigned short ch = *p++;
+ ch |= ((unsigned short)*p++) << 8;
+ if(ch >= 0xd800 && ch <= 0xdfff){
+ static int once;
+ if(!once++)
+ fprintf(stderr, "Warning: utf-16 unsupported, please report\n");
+ }
+ if(ch >= 0x800){
+ if(pbuf - namebuf + 3 >= sizeof(namebuf))
+ break;
+ *pbuf++ = 0xe0 | ((ch >> 12) & 0x0f);
+ *pbuf++ = 0x80 | ((ch >> 6) & 0x3f);
+ *pbuf++ = 0x80 | ( ch & 0x3f);
+ continue;
+ }
+ if(ch >= 0x80){
+ if(pbuf - namebuf + 2 >= sizeof(namebuf))
+ break;
+ *pbuf++ = 0xc0 | ((ch >> 6) & 0x1f);
+ *pbuf++ = 0x80 | ( ch & 0x3f);
+ continue;
+ }
+ if (pbuf - namebuf + 1 >= sizeof(namebuf))
+ break;
+ *pbuf++ = ch;
+ }
+ *pbuf = 0;
+ return namebuf;
+ }
+ p += l + 2;
+ }
+ return NULL;
+}
+
u_char* lltd_extract_ip(const u_char*p){
u_char l;
static u_char buf[20];
View
4 lltdscan.8
@@ -5,13 +5,15 @@
lltdscan \- scan for LLTD-enabled hosts on a network interface\&.
.PP
.SH "SYNOPSIS"
-\fBlltdscan\fP [-i \fIiface\fP] [-t \fItimeout\fP] [-v] [-v] [aa:bb:cc:dd:ee:ff]
+\fBlltdscan\fP [-i \fIiface\fP] [-t \fItimeout\fP] [-u] [-v] [-v] [aa:bb:cc:dd:ee:ff]
.PP
.SH "DESCRIPTION"
The \fIlltdscan\fP utility sends broadcast \fBLLTD\fP request on specified (or default) interface. And then listens for \fBtimeout\fP milliseconds for responses\&.
.PP
Add one or two \fB-v\fP options to increase verbosity\&.
.PP
+Add \fB-u\fP option to show machine names in UTF-8\&.
+.PP
Also you can specify exactly one \fBMAC\fP address as last argument - and \fBlltdscan\fP will exit as soon as it receives first reply from specified host\&.
.SH "LLTD PROTOCOL"
\fBLLTD\fP stands for "Link Layer Topology Discovery"\&.
View
14 lltdscan.c
@@ -10,7 +10,11 @@
void usage(char *name) {
fprintf(stderr,
- "usage: %s [-i iface] [-t timeout] [-v] [-v] [aa:bb:cc:dd:ee:ff]\n",
+ "usage: %s [-i iface] [-t timeout] [-u] [-v] [-v] [aa:bb:cc:dd:ee:ff]\n\n"
+ "\t timeout is in milliseconds;\n"
+ "\t add -u to show machine names in UTF-8;\n"
+ "\t add -v or -vv increase verbosity;\n"
+ "\t last argument is an optional single MAC-address of interest.\n",
name);
}
@@ -18,6 +22,7 @@ static int do_stop=0;
static timer_t timer_id;
static struct timeval start_time;
static int verbose = 0;
+static int unicode = 0;
static uint64_t hosts[200];
static int nhosts = 0;
@@ -79,7 +84,7 @@ void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *pa
mac,
lltd_extract_ip(packet+46),
tv_diff2msec(&header->ts),
- lltd_extract_name(packet+46)
+ unicode ? lltd_extract_unicode_name(packet+46) : lltd_extract_name(packet+46)
);
if(verbose == 1){
@@ -124,7 +129,7 @@ int main (int argc, char *argv[]){
memset(&tspec, 0, sizeof(tspec));
tspec.it_value.tv_sec = 3;
- while ((c = getopt(argc, argv, "t:i:hv")) != EOF) {
+ while ((c = getopt(argc, argv, "t:i:hvu")) != EOF) {
switch (c) {
case 'i': // interface
dev = optarg;
@@ -142,6 +147,9 @@ int main (int argc, char *argv[]){
case 'v': // verbosity
verbose++;
break;
+ case 'u': // unicode support
+ unicode = 1;
+ break;
case 'h': // show usage
usage(argv[0]);
exit(EXIT_SUCCESS);

0 comments on commit 939327b

Please sign in to comment.
Something went wrong with that request. Please try again.