diff options
| author | Håkon Nessjøen <haakon.nessjoen@gmail.com> | 2011-02-24 16:46:30 +0100 |
|---|---|---|
| committer | Håkon Nessjøen <haakon.nessjoen@gmail.com> | 2011-02-24 16:46:30 +0100 |
| commit | cb6fe86292fd85a67dfd930cdc351fec0ddf96bc (patch) | |
| tree | 1c60d781bddc739e66473a7a1d649e17da63970e /protocol.c | |
| parent | f77147c698364fb38c226895556176abd61d3217 (diff) | |
| download | MAC-Telnet-cb6fe86292fd85a67dfd930cdc351fec0ddf96bc.tar.gz MAC-Telnet-cb6fe86292fd85a67dfd930cdc351fec0ddf96bc.zip | |
Code cleanup
Diffstat (limited to 'protocol.c')
| -rw-r--r-- | protocol.c | 53 |
1 files changed, 53 insertions, 0 deletions
@@ -472,3 +472,56 @@ done: close(sock); return 0; } + +/* + * This function accepts either a full MAC address using : or - as seperators. + * Or a router hostname. The hostname will be searched for via MNDP broadcast packets. + */ +int query_mndp_verbose(char *address, unsigned char *dstmac) { + char *p = address; + int colons = 0; + int dashs = 0; + + while (*p++) { + if (*p == ':') { + colons++; + } + else if (*p == '-') { + dashs++; + } + } + + /* + * Windows users often enter macs with dash instead + * of colon. + */ + if (colons == 0 && dashs == 5) { + p = address; + while (*p++) { + if (*p == '-') { + *p = ':'; + } + } + colons = dashs; + } + + if (colons != 5) { + /* + * Not a valid mac-address. + * Search for Router by identity name, using MNDP + */ + fprintf(stderr, "Searching for '%s'...", address); + if (!query_mndp(address, dstmac)) { + fprintf(stderr, "not found\n"); + return 0; + } + + /* Router found, display mac and continue */ + fprintf(stderr, "found\n"); + } else { + /* Convert mac address string to ether_addr struct */ + ether_aton_r(address, (struct ether_addr *)dstmac); + } + + return 1; +} |
