--- ./sipp.cpp.orig	2013-09-23 15:05:15.164194852 +0000
+++ ./sipp.cpp	2013-09-23 15:07:12.685491835 +0000
@@ -1989,8 +1989,15 @@
   }
 }
 
+static int stdin_mode;
+void reset_stdin_socket() {
+  fcntl(fileno(stdin), F_SETFL, stdin_mode);
+}
+
 void setup_stdin_socket() {
-  fcntl(fileno(stdin), F_SETFL, fcntl(fileno(stdin), F_GETFL) | O_NONBLOCK);
+  stdin_mode = fcntl(fileno(stdin), F_GETFL);
+  atexit(reset_stdin_socket);
+  fcntl(fileno(stdin), F_SETFL, stdin_mode | O_NONBLOCK);
   stdin_socket = sipp_allocate_socket(0, T_UDP, fileno(stdin), 0);
   if (!stdin_socket) {
     ERROR_NO("Could not setup keyboard (stdin) socket!\n");
