summaryrefslogtreecommitdiff
path: root/mactelnet.c
diff options
context:
space:
mode:
Diffstat (limited to 'mactelnet.c')
-rw-r--r--mactelnet.c54
1 files changed, 31 insertions, 23 deletions
diff --git a/mactelnet.c b/mactelnet.c
index ca27f15..c78b262 100644
--- a/mactelnet.c
+++ b/mactelnet.c
@@ -1,4 +1,4 @@
-/*find
+/*
Mac-Telnet - Connect to RouterOS or mactelnetd devices via MAC address
Copyright (C) 2010, Håkon Nessjøen <haakon.nessjoen@gmail.com>
@@ -17,6 +17,8 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define _BSD_SOURCE
+#include <libintl.h>
+#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
@@ -44,6 +46,8 @@
#define PROGRAM_NAME "MAC-Telnet"
+#define _(String) gettext (String)
+
static int sockfd = 0;
static int insockfd;
@@ -147,7 +151,7 @@ static int send_udp(struct mt_packet *packet, int retransmit) {
reset_term();
}
- fprintf(stderr, "\nConnection timed out\n");
+ fprintf(stderr, _("\nConnection timed out\n"));
exit(1);
}
return sent_bytes;
@@ -296,13 +300,13 @@ static int handle_packet(unsigned char *data, int data_len) {
send_udp(&odata, 0);
if (!quiet_mode) {
- fprintf(stderr, "Connection closed.\n");
+ fprintf(stderr, _("Connection closed.\n"));
}
/* exit */
running = 0;
} else {
- fprintf(stderr, "Unhandeled packet type: %d received from server %s\n", pkthdr.ptype, ether_ntoa((struct ether_addr *)dstmac));
+ fprintf(stderr, _("Unhandeled packet type: %d received from server %s\n"), pkthdr.ptype, ether_ntoa((struct ether_addr *)dstmac));
return -1;
}
@@ -324,7 +328,7 @@ static int find_interface() {
bzero(emptymac, ETH_ALEN);
if (net_get_interfaces(interfaces, MAX_INTERFACES) <= 0) {
- fprintf(stderr, "Error: No suitable devices found\n");
+ fprintf(stderr, _("Error: No suitable devices found\n"));
exit(1);
}
@@ -399,6 +403,10 @@ int main (int argc, char **argv) {
int c;
int optval = 1;
+ setlocale(LC_ALL, "");
+ bindtextdomain("mactelnet","/usr/share/locale");
+ textdomain("mactelnet");
+
while (1) {
c = getopt(argc, argv, "nqt:u:p:vh?");
@@ -448,19 +456,19 @@ 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>]\n"), argv[0]);
if (print_help) {
- fprintf(stderr, "\nParameters:\n");
- fprintf(stderr, " MAC MAC-Address of the RouterOS/mactelnetd device. Use mndp to discover it.\n");
- fprintf(stderr, " identity The identity/name of your destination device. Uses MNDP protocol to find it.\n");
- fprintf(stderr, " -n Do not use broadcast packets. Less insecure but requires root privileges.\n");
- fprintf(stderr, " -t Amount of seconds to wait for a response on each interface.\n");
- fprintf(stderr, " -u Specify username on command line.\n");
- fprintf(stderr, " -p Specify password on command line.\n");
- fprintf(stderr, " -q Quiet mode.\n");
- fprintf(stderr, " -h This help.\n");
- fprintf(stderr, "\n");
+ 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"
+ " -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"
+ " -p Specify password on command line.\n"
+ " -q Quiet mode.\n"
+ " -h This help.\n"
+ "\n"));
}
return 1;
}
@@ -475,7 +483,7 @@ int main (int argc, char **argv) {
if (use_raw_socket) {
if (geteuid() != 0) {
- fprintf(stderr, "You need to have root privileges to use the -n parameter.\n");
+ fprintf(stderr, _("You need to have root privileges to use the -n parameter.\n"));
return 1;
}
@@ -507,14 +515,14 @@ int main (int argc, char **argv) {
if (!have_username) {
if (!quiet_mode) {
- printf("Login: ");
+ printf(_("Login: "));
}
scanf("%254s", username);
}
if (!have_password) {
char *tmp;
- tmp = getpass(quiet_mode ? "" : "Password: ");
+ tmp = getpass(quiet_mode ? "" : _("Password: "));
strncpy(password, tmp, sizeof(password) - 1);
password[sizeof(password) - 1] = '\0';
/* security */
@@ -539,7 +547,7 @@ int main (int argc, char **argv) {
setvbuf(stdout, (char*)NULL, _IONBF, 0);
if (!quiet_mode) {
- printf("Connecting to %s...", ether_ntoa((struct ether_addr *)dstmac));
+ printf(_("Connecting to %s..."), ether_ntoa((struct ether_addr *)dstmac));
}
/* Initialize receiving socket on the device chosen */
@@ -549,16 +557,16 @@ int main (int argc, char **argv) {
/* Bind to udp port */
if (bind(insockfd, (struct sockaddr *)&si_me, sizeof(si_me)) == -1) {
- fprintf(stderr, "Error binding to %s:%d, %s\n", inet_ntoa(si_me.sin_addr), sourceport, strerror(errno));
+ fprintf(stderr, _("Error binding to %s:%d, %s\n"), inet_ntoa(si_me.sin_addr), sourceport, strerror(errno));
return 1;
}
if (!find_interface() || (result = recvfrom(insockfd, buff, 1400, 0, 0, 0)) < 1) {
- fprintf(stderr, "Connection failed.\n");
+ fprintf(stderr, _("Connection failed.\n"));
return 1;
}
if (!quiet_mode) {
- printf("done\n");
+ printf(_("done\n"));
}
/* Handle first received packet */