Figure 5. Flushing terminal I/O on receipt of out of band data.

     #include <sys/ioctl.h>
     #include <sys/file.h>
     ... 
     oob() { 
          int out = FWRITE, mark; 
          char waste[BUFSIZ];

          /* flush local terminal output */ 
          ioctl(1, TIOCFLUSH, (char *)&out); 
          for (;;) { 
               if (ioctl(rem, SIOCATMARK, &mark) < 0) { 
                    perror("ioctl"); 
                    break; 
               } 
               if (mark) 
                    break;
               (void) read(rem, waste, sizeof (waste)); 
          } 
          if (recv(rem, &mark, 1, MSG_OOB) < 0) { 
               perror("recv"); 
               ... 
          } 
          ... 
     }