Examples of termios change functions. All know flags (I hope): IFLAGS (BRKINT|ICRNL|IGNBRK|IGNCR|IGNPAR|IMAXBEL|INLCR|INPCK|ISTRIP|IUCLC|IUTF8|IXANY|IXOFF|IXON|PARMRK) OFLAGS (BSDLY|CRDLY|FFDLY|NLDLY|OCRNL|OFDEL|OFILL|OLCUC|ONLCR|ONLRET|ONOCR|ONOEOT|OPOST|OXTABS|TABDLY|VTDLY) CFLAGS (CCTS_OFLOW|CIGNORE|CIBAUD|CLOCAL|CMSPAR|CREAD|CRTS_IFLOW|CRTSCTS|CSIZE|CSTOPB|HUPCL|MDMBUF| LOBLK|PARENB|PARODD|CBAUD|CBAUDEX) LFLAGS (ALTWERASE|DEFECHO|ECHO|ECHOCTL|ECHOE|ECHOK|ECHOKE|ECHONL|ECHOPRT|FLUSHO|ICANON|IEXTEN|ISIG| NOFLSH|NOKERNINFO|PENDIN|TOSTOP|XCASE) struct termios *termfunc(struct termios *term) { speed_t baud_bits = B38400; term->c_iflag &= ~( BRKINT|ICRNL| IGNCR| IMAXBEL|INLCR|INPCK|ISTRIP|IUCLC|IUTF8|IXANY|IXOFF|IXON|PARMRK ); term->c_iflag |= ( IGNBRK| IGNPAR ); term->c_oflag &= ~( OCRNL|OFDEL|OFILL|OLCUC|ONLCR|ONLRET|ONOCR|OPOST|BSDLY|CRDLY|FFDLY|NLDLY|VTDLY ); term->c_oflag |= ( BS0 |CR0 |FF0 |NL0 |VT0 ); term->c_cflag &= ~( CMSPAR |CRTSCTS|CSTOPB|HUPCL|PARENB|PARODD|CSIZE ); term->c_cflag |= ( CLOCAL |CREAD |CS8 ); term->c_lflag &= ~( ECHO|ECHOCTL|ECHOE|ECHOK|ECHOKE|ECHONL|ECHOPRT|FLUSHO|ICANON|IEXTEN|ISIG|NOFLSH|PENDIN|TOSTOP|XCASE ); term->c_lflag |= ( ); cfsetispeed( term, baud_bits ); cfsetospeed( term, baud_bits ); termiosCharClr(term); term->c_cc[VMIN] = 1; term->c_cc[VTIME] = 0; return term; } /*** Hmm, what would a good default setting be ? ***/ struct termios *termios_def(struct termios *term) { if (term == NULL) { return term; } memset( term, 0, sizeof(struct termios)); term->c_iflag &= ~(IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|IUCLC|IXANY|IMAXBEL); term->c_iflag |= (ICRNL|IXON|IXOFF); term->c_oflag &= ~(OLCUC|OCRNL|ONOCR|ONLRET|OFILL|OFDEL|NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY); term->c_oflag |= (OPOST|ONLCR|NL0|CR0|TAB0|BS0|VT0|FF0); term->c_cflag &= ~(PARENB|PARODD|CSIZE|CSTOPB|CLOCAL|CRTSCTS); term->c_cflag |= (CS8|HUPCL|CREAD); term->c_lflag &= ~(IEXTEN|ECHONL|NOFLSH|XCASE|TOSTOP|ECHOPRT); term->c_lflag |= (ISIG|ICANON|ECHO|ECHOE|ECHOK|ECHOCTL|ECHOKE); cfsetispeed( term, B9600 ); cfsetospeed( term, B9600 ); termiosCharDef(term); return term; } /*** stty lookalikes ***/ struct termios *termios_sane(struct termios *term) { /* as in "stty sane" */ if (term == NULL) { return term; } term->c_iflag &= ~(IGNBRK|INLCR|IGNCR|IXOFF|IUCLC|IXANY|IUTF8); term->c_iflag |= (BRKINT|ICRNL|IMAXBEL); term->c_oflag &= ~(OLCUC|OCRNL|ONOCR|ONLRET|OFILL|OFDEL|NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY); term->c_oflag |= (OPOST|ONLCR|NL0|CR0|TAB0|BS0|VT0|FF0); term->c_cflag &= ~(0); term->c_cflag |= (CREAD); term->c_lflag &= ~(ECHONL|NOFLSH|XCASE|TOSTOP|ECHOPRT|EXTPROC|FLUSHO); term->c_lflag |= (ISIG|ICANON|IEXTEN|ECHO|ECHOE|ECHOK|ECHOCTL|ECHOKE); termiosCharDef(term); return term; } struct termios *termios_cooked(struct termios *term) { /* as in "stty cooked" */ if (term == NULL) { return term; } term->c_iflag &= ~(0); term->c_iflag |= (BRKINT|IGNPAR|ISTRIP|ICRNL|IXON); term->c_oflag &= ~(0); term->c_oflag |= (OPOST); term->c_cflag &= ~(0); term->c_cflag |= (0); term->c_lflag &= ~(0); term->c_lflag |= (ISIG|ICANON); term->c_cc[VEOF] = CTRL('D'); term->c_cc[VEOL] = _POSIX_VDISABLE; term->c_cc[VEOL2] = _POSIX_VDISABLE; return term; } struct termios *termios_raw(struct termios *term) { /* as in "stty raw" */ if (term == NULL) { return term; } /* clib function cfmakeraw()'s choises in comments, use whatever suits you */ /* cfmakeraw: ~(IGNBRK|BRKINT |PARMRK |ISTRIP|INLCR|IGNCR|ICRNL|IXON) */ term->c_iflag &= ~(IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF|IUCLC|IXANY|IMAXBEL); term->c_iflag |= (0); /* cfmakeraw: ~(OPOST) */ term->c_oflag &= ~(OPOST); term->c_oflag |= (0); /* cfmakeraw: ~(CSIZE|PARENB) */ term->c_cflag &= ~(0); /* cfmakeraw: (CS8) */ term->c_cflag |= (0); /* cfmakeraw: ~(ECHO|ECHONL|ISIG|ICANON |IEXTEN) */ term->c_lflag &= ~( ISIG|ICANON|XCASE); term->c_lflag |= (0); /* cfmakeraw: no change to theese */ term->c_cc[VMIN] = 1; term->c_cc[VTIME] = 0; return term; } struct termios *termios_raw2(struct termios *term) { /* 8n1 nomodem nortscts */ if (term == NULL) { return term; } /*(void) termios_def(term); */ memset(term, 0, sizeof(struct termios)); /* cfmakeraw: ~(ISTRIP|INLCR|IGNCR|ICRNL|IXON|BRKINT |IGNBRK|PARMRK) */ /*term->c_iflag &= ~(ISTRIP|INLCR|IGNCR|ICRNL|IXON|BRKINT |INPCK|IUCLC|IXANY|IXOFF); */ term->c_iflag |= (IGNBRK|IGNPAR); /* cfmakeraw: ~(OPOST) */ /*term->c_oflag &= ~(OPOST |OLCUC|ONLCR|OCRNL|ONOCR|ONLRET|OFILL); */ term->c_oflag |= (0); /* cfmakeraw: ~(CSIZE|PARENB) */ /*term->c_cflag &= ~(CSIZE|PARENB |HUPCL|CSTOPB|CRTSCTS); */ /* cfmakeraw: (CS8) */ term->c_cflag |= (CS8 |CREAD|CLOCAL); /* cfmakeraw: ~(ECHO|ISIG|ICANON|IEXTEN|ECHONL) */ /*term->c_lflag &= ~(ECHO|ISIG|ICANON|IEXTEN|ECHONL |NOFLSH|TOSTOP); */ term->c_lflag |= (0); (void) cfsetispeed( term, B9600 ); (void) cfsetospeed( term, B9600 ); (void) termiosCharDef(term); /* cfmakeraw: no change to theese */ term->c_cc[VMIN] = 1; term->c_cc[VTIME] = 0; return term; } struct termios *termios_rawline(struct termios *term) { if (term == NULL) { return term; } memset( term, 0, sizeof(struct termios)); /* term->c_iflag &= ~(); */ term->c_iflag |= (IGNPAR|IGNCR); /* term->c_oflag &= ~(); */ /* term->c_oflag |= (); */ /* term->c_cflag &= ~(); */ term->c_cflag |= (CS8|CREAD|CLOCAL); /* HUPCL|CRTSCTS */ /* term->c_lflag &= ~(); */ term->c_lflag |= (ICANON); /* ECHO|ECHOE|ECHOK|ECHOCTL|ECHOKE */ termiosCharClr(term); return term; } struct termios *termios_7e1(struct termios *term) { if (term == NULL) { return term; } term->c_cflag &= ~(CSIZE|PARODD|CSTOPB); term->c_cflag |= (CS7|PARENB); return term; } struct termios *termios_8n1(struct termios *term) { if (term == NULL) { return term; } term->c_cflag &= ~(CSIZE|PARENB|CSTOPB); term->c_cflag |= (CS8); return term; } /* I have used this in a pty atermlication, spying on data through serial port */ struct termios *termios_clr(struct termios *term) { if (term == NULL) { return term; } termios_def(term); term->c_iflag &= ~(ICRNL|IXON|IXOFF); /* term->c_iflag |= (0); */ term->c_oflag &= ~(OPOST|ONLCR); /* term->c_oflag |= (0); */ term->c_cflag &= ~(HUPCL); term->c_cflag |= (CLOCAL); term->c_lflag &= ~(ISIG|ICANON|ECHO|ECHOCTL); /* term->c_lflag |= (0); */ return term; }