Re: [suse-programming-e] echoing on a socket
alan@ibgames.com writes:
Hi,
I need to turn off the echo on a socket while I get a password.
I tried:
struct termios termios_p; tcgetattr(sd,&termios_p); termios_p.c_lflag &= ~ECHO; tcsetattr(sd,TCSANOW,&termios_p);
where sd is the socket descriptor.
It didn't seem to make any difference. Am I doing something wrong, or is this not the way it is done these days?
Can any one assist, please?
Your socket is not necessarily a terminal (that is what pseudo terminals are for) what exactly is on both sides of this socket? Also you should check the error returns like so: #include <termios.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> int main(void) { struct termios termios_p; int sd = 0; if(isatty(sd)) { fprintf(stderr, "sd is a terminal\n"); } else { fprintf(stderr, "sd is NOT a terminal\n"); } if(tcgetattr(sd,&termios_p)) { perror("tcgetattr failed"); exit(EXIT_FAILURE); } termios_p.c_lflag &= ~ECHO; if(tcsetattr(sd,TCSANOW,&termios_p)) { perror("tcsetattr failed"); exit(EXIT_FAILURE); } return 0; }
participants (1)
-
Mark Gray