summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHåkon Nessjøen <haakon.nessjoen@gmail.com>2012-05-20 16:53:56 +0200
committerHåkon Nessjøen <haakon.nessjoen@gmail.com>2012-05-20 16:53:56 +0200
commit7175eb2a1d83ae10a7bc0c1961a6d13fb40a1456 (patch)
treedd9ee784048ad17a21230e70c516ee60777618bc
parent2d1bb7ebafb3cfe9161854d1ac0b05133fa05139 (diff)
downloadMAC-Telnet-7175eb2a1d83ae10a7bc0c1961a6d13fb40a1456.tar.gz
MAC-Telnet-7175eb2a1d83ae10a7bc0c1961a6d13fb40a1456.zip
Added -l option to mactelnet, so you don't have to know about the mndp tool to find it.
-rw-r--r--Makefile4
-rw-r--r--docs/mactelnet.17
-rw-r--r--mactelnet.c10
-rw-r--r--mndp.c13
-rw-r--r--mndp.h6
5 files changed, 36 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 15a73c1..5b9ae91 100644
--- a/Makefile
+++ b/Makefile
@@ -42,8 +42,8 @@ interfaces.o: interfaces.c interfaces.h
md5.o: md5.c md5.h
${CC} -Wall ${CFLAGS} -c md5.c
-mactelnet: config.h mactelnet.c mactelnet.h protocol.o console.c console.h interfaces.o md5.o
- ${CC} -Wall ${CFLAGS} ${LDFLAGS} -o mactelnet mactelnet.c protocol.o console.c interfaces.o md5.o ${LIBS}
+mactelnet: config.h mactelnet.c mactelnet.h protocol.o console.c console.h interfaces.o md5.o mndp.c
+ ${CC} -Wall ${CFLAGS} ${LDFLAGS} -o mactelnet mactelnet.c protocol.o console.c interfaces.o md5.o -DFROM_MACTELNET mndp.c ${LIBS}
mactelnetd: config.h mactelnetd.c protocol.o interfaces.o console.c console.h users.o users.h md5.o
${CC} -Wall ${CFLAGS} ${LDFLAGS} -o mactelnetd mactelnetd.c protocol.o console.c interfaces.o users.o md5.o ${LIBS}
diff --git a/docs/mactelnet.1 b/docs/mactelnet.1
index 7ca091e..d29591d 100644
--- a/docs/mactelnet.1
+++ b/docs/mactelnet.1
@@ -12,6 +12,13 @@ If specified, the hostname (identity) will be looked up via MNDP discovery.
These programs follow the usual GNU command line syntax.
A summary of options is included below.
.TP
+.B \-l
+This will discover RouterOS or MAC-Telnetd enabled devices. It will
+list the MAC-address software version, and uptime of every device
+or machine it discovers. To exit the discovery, use
+.B Control + C
+\.
+.TP
.B \-n
Do not use broadcast packets. A tad less insecure but requires root privileges.
This means that ethernet packets will have the specified mac-address as the packet
diff --git a/mactelnet.c b/mactelnet.c
index c78b262..6f2ec80 100644
--- a/mactelnet.c
+++ b/mactelnet.c
@@ -43,6 +43,7 @@
#include "interfaces.h"
#include "config.h"
#include "mactelnet.h"
+#include "mndp.h"
#define PROGRAM_NAME "MAC-Telnet"
@@ -408,7 +409,7 @@ int main (int argc, char **argv) {
textdomain("mactelnet");
while (1) {
- c = getopt(argc, argv, "nqt:u:p:vh?");
+ c = getopt(argc, argv, "lnqt:u:p:vh?");
if (c == -1) {
break;
@@ -447,6 +448,10 @@ int main (int argc, char **argv) {
quiet_mode = 1;
break;
+ case 'l':
+ return mndp();
+ break;
+
case 'h':
case '?':
print_help = 1;
@@ -456,12 +461,13 @@ int main (int argc, char **argv) {
}
if (argc - optind < 1 || print_help) {
print_version();
- fprintf(stderr, _("Usage: %s <MAC|identity> [-h] [-n] [-t <timeout>] [-u <username>] [-p <password>]\n"), argv[0]);
+ fprintf(stderr, _("Usage: %s <MAC|identity> [-h] [-n] [-t <timeout>] [-u <username>] [-p <password>] | <-l>\n"), argv[0]);
if (print_help) {
fprintf(stderr, _("\nParameters:\n"
" MAC MAC-Address of the RouterOS/mactelnetd device. Use mndp to discover it.\n"
" identity The identity/name of your destination device. Uses MNDP protocol to find it.\n"
+ " -l List/Search for routers nearby. (using MNDP)\n"
" -n Do not use broadcast packets. Less insecure but requires root privileges.\n"
" -t Amount of seconds to wait for a response on each interface.\n"
" -u Specify username on command line.\n"
diff --git a/mndp.c b/mndp.c
index 1b070e2..bec7c64 100644
--- a/mndp.c
+++ b/mndp.c
@@ -28,15 +28,26 @@
#define _(String) gettext (String)
+/* This file is also used for the -l option in mactelnet */
+#ifndef FROM_MACTELNET
+
/* Protocol data direction, not used here, but obligatory for protocol.c */
unsigned char mt_direction_fromserver = 0;
int main(int argc, char **argv) {
+#else
+int mndp(void) {
+#endif
int sock,result;
int optval = 1;
struct sockaddr_in si_me, si_remote;
unsigned char buff[MT_PACKET_LEN];
+#ifdef FROM_MACTELNET
+ /* mactelnet.c has this set to 1 */
+ mt_direction_fromserver = 0;
+#endif
+
setlocale(LC_ALL, "");
bindtextdomain("mactelnet","/usr/share/locale");
textdomain("mactelnet");
@@ -77,6 +88,8 @@ int main(int argc, char **argv) {
}
}
+ printf("\n\E[1m%-17s Identity (platform version hardware) uptime\E[m\n", "MAC-Address");
+
while(1) {
struct mt_mndp_info *packet;
/* Wait for a UDP packet */
diff --git a/mndp.h b/mndp.h
new file mode 100644
index 0000000..77c489f
--- /dev/null
+++ b/mndp.h
@@ -0,0 +1,6 @@
+#ifndef _MNDP_H
+#define _MNDP_H
+
+int mndp(void);
+
+#endif \ No newline at end of file