From d4d5c5495ef48bdd00c4d47d94996ebadbf2b906 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Fri, 20 Nov 2009 16:06:51 +0000 Subject: [PATCH] nfc-relay: Capture ctrl-c for quitting cleanly the relay attack application. --- src/examples/nfc-relay.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/examples/nfc-relay.c b/src/examples/nfc-relay.c index 5984387..e395bc6 100644 --- a/src/examples/nfc-relay.c +++ b/src/examples/nfc-relay.c @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -39,6 +40,14 @@ static byte_t abtTagRxPar[MAX_FRAME_LEN]; static size_t szTagRxBits; static dev_info* pdiReader; static dev_info* pdiTag; +static bool quitting=false; + +void intr_hdlr(void) +{ + printf("\nQuitting...\n"); + quitting=true; + return; +} void print_usage(char* argv[]) { @@ -68,6 +77,12 @@ int main(int argc,char* argv[]) } } +#ifdef WIN32 + signal(SIGINT, (void (__cdecl*)(int)) intr_hdlr); +#else + signal(SIGINT, (void (*)()) intr_hdlr); +#endif + // Try to open the NFC emulator device pdiTag = nfc_connect(NULL); if (pdiTag == INVALID_DEVICE_INFO) @@ -102,7 +117,7 @@ int main(int argc,char* argv[]) nfc_configure(pdiReader,DCO_ACCEPT_INVALID_FRAMES,true); printf("[+] Done, relaying frames now!\n\n"); - while(true) + while(!quitting) { // Test if we received a frame from the reader if (nfc_target_receive_bits(pdiTag,abtReaderRx,&szReaderRxBits,abtReaderRxPar))