diff options
Diffstat (limited to 'mndp.c')
-rw-r--r-- | mndp.c | 20 |
1 files changed, 14 insertions, 6 deletions
@@ -16,6 +16,8 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include <libintl.h> +#include <locale.h> #include <stdlib.h> #include <stdio.h> #include <arpa/inet.h> @@ -24,6 +26,8 @@ #include "protocol.h" #include "config.h" +#define _(String) gettext (String) + /* Protocol data direction, not used here, but obligatory for protocol.c */ unsigned char mt_direction_fromserver = 0; @@ -33,6 +37,10 @@ int main(int argc, char **argv) { struct sockaddr_in si_me, si_remote; unsigned char buff[MT_PACKET_LEN]; + setlocale(LC_ALL, ""); + bindtextdomain("mactelnet","/usr/share/locale"); + textdomain("mactelnet"); + /* Open a UDP socket handle */ sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); @@ -46,16 +54,16 @@ int main(int argc, char **argv) { /* Bind to specified address/port */ if (bind(sock, (struct sockaddr *)&si_me, sizeof(si_me))==-1) { - fprintf(stderr, "Error binding to %s:%d\n", inet_ntoa(si_me.sin_addr), MT_MNDP_PORT); + fprintf(stderr, _("Error binding to %s:%d\n"), inet_ntoa(si_me.sin_addr), MT_MNDP_PORT); return 1; } /* Write informative message to STDERR to make it easier to use the output in simple scripts */ - fprintf(stderr, "Searching for MikroTik routers... Abort with CTRL+C.\n"); + fprintf(stderr, _("Searching for MikroTik routers... Abort with CTRL+C.\n")); /* Set the socket to allow sending broadcast packets */ if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &optval, sizeof (optval))==-1) { - fprintf(stderr, "Unable to send broadcast packets: Operating in receive only mode.\n"); + fprintf(stderr, _("Unable to send broadcast packets: Operating in receive only mode.\n")); } else { /* Request routers identify themselves */ unsigned int message = 0; @@ -65,7 +73,7 @@ int main(int argc, char **argv) { si_remote.sin_port = htons(MT_MNDP_PORT); si_remote.sin_addr.s_addr = htonl(INADDR_BROADCAST); if (sendto (sock, &message, sizeof (message), 0, (struct sockaddr *)&si_remote, sizeof(si_remote))==-1) { - fprintf(stderr, "Unable to send broadcast packet: Operating in receive only mode.\n"); + fprintf(stderr, _("Unable to send broadcast packet: Operating in receive only mode.\n")); } } @@ -74,7 +82,7 @@ int main(int argc, char **argv) { /* Wait for a UDP packet */ result = recvfrom(sock, buff, MT_PACKET_LEN, 0, 0, 0); if (result < 0) { - fprintf(stderr, "Error occured. aborting\n"); + fprintf(stderr, _("An error occured. aborting\n")); exit(1); } @@ -88,7 +96,7 @@ int main(int argc, char **argv) { printf(" (%s %s %s)", packet->platform, packet->version, packet->hardware); } if (packet->uptime > 0) { - printf(" up %d days %d hours", packet->uptime / 86400, packet->uptime % 86400 / 3600); + printf(_(" up %d days %d hours"), packet->uptime / 86400, packet->uptime % 86400 / 3600); } putchar('\n'); } |