From 56d1d9b993e28db228713f398e8402d000c6353d Mon Sep 17 00:00:00 2001 From: Håkon Nessjøen Date: Tue, 8 Jan 2013 16:30:07 +0100 Subject: Added -t timeout option to -l option on mactelnet. --- mactelnet.c | 2 +- mndp.c | 17 ++++++++++++++++- mndp.h | 4 ++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/mactelnet.c b/mactelnet.c index ad2c985..e48e4db 100644 --- a/mactelnet.c +++ b/mactelnet.c @@ -483,7 +483,7 @@ int main (int argc, char **argv) { break; case 'l': - return mndp(); + return mndp(connect_timeout); break; case 'h': diff --git a/mndp.c b/mndp.c index e8ba8e3..986476e 100644 --- a/mndp.c +++ b/mndp.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include #include @@ -36,7 +38,13 @@ unsigned char mt_direction_fromserver = 0; int main(int argc, char **argv) { #else -int mndp(void) { + +void sig_alarm(int signo) +{ + exit(0); +} + +int mndp(int timeout) { #endif int sock,result; int optval = 1; @@ -46,6 +54,7 @@ int mndp(void) { #ifdef FROM_MACTELNET /* mactelnet.c has this set to 1 */ mt_direction_fromserver = 0; + signal(SIGALRM, sig_alarm); #endif setlocale(LC_ALL, ""); @@ -90,6 +99,12 @@ int mndp(void) { printf("\n\E[1m%-17s %s\E[m\n", _("MAC-Address"), _("Identity (platform version hardware) uptime")); +#ifdef FROM_MACTELNET + if (timeout > 0) { + alarm(timeout); + } +#endif + while(1) { struct mt_mndp_info *packet; /* Wait for a UDP packet */ diff --git a/mndp.h b/mndp.h index 77c489f..65c3a51 100644 --- a/mndp.h +++ b/mndp.h @@ -1,6 +1,6 @@ #ifndef _MNDP_H #define _MNDP_H -int mndp(void); +int mndp(int timeout); -#endif \ No newline at end of file +#endif -- cgit v1.2.3