user1747781
user1747781

Reputation: 35

telnet catch ctrl+c server


I have written a socket-server like here. If I type ctrl+c in telnet, the server don't do anything now. I want to catch it like signal(SIGINT,SIG_IGN)
How can I do?

Upvotes: 1

Views: 2122

Answers (2)

Brian White
Brian White

Reputation: 8756

The telnet program catches the CTRL-C character and sends it as a single byte (\x03) down the TCP connection to the other side. It's up to the receiving program to decide what to do with that byte.

In the case of it being received by a "telnet daemon" intending to provide console-like interactivity via a pseudo-terminal, that combination generates a SIGINT to the process running under it, usually a shell.

So, to answer your question, you can either process the received \x03 character and internally generate a SIGINT or you can run your entire program as a process spawned and controlled by telnetd under a pseudo-terminal.

Upvotes: 2

wildplasser
wildplasser

Reputation: 44250

The telnet client (the process that recieves the SIGINT) should process it: either handle it locally (eg: terminate, or re-issue a prompt), or send it to the server as IAC something (BRK?) and/or out-of band data. If you want to pass the interrupt to the server, Google for "telnet IAC" will probably get you started.

Upvotes: 0

Related Questions