I have an embedded system that is programed in C. I need to do the equivalent to the DOS command Telnet. The idea is to test if the remote host is up and running.
I would like to have some orientation here like:
Open source project that I can use as a guide line (C language)
Some documentation on what the Telnet command does (so I can
implement my own)
Thanks
Update: Thank you for your valuable comments
My system connects to a host via GPRS/Ethernet/dial up/Wifi (one of them). As a developer I check if the host is ok by using my windows laptop (with a Dial up modem, GPRS modem or whatever is needed) and running Telnet like this:
telnet 192.168.0.1 8000
(non real values)
If the host is ok I got the clean screen, otherwise I got an error. That's what I need to do in code, to be able to determine if the host is up and running by using a sort of DOS telnet client command in C.
This is done once, just to check communications, after this test is cleared the real info should be sent.
Related
I made a simple tcp client in C (in windows I precise), which is controlled by netcat. I would like to be able to run a command line executable (such as Strings for example) remotely, and above all to be able to interact from netcat or my server with this programme.( (in order to perform actions on the remote computer in particular).
What would be the best solution to do that ?
edit : Here is an example : I want to run String programm on the remote computer. To do that, I can simply write "string" in netcat, this command would be interpreted by client, and this client execute strings binary. The output of strings should be displayed on netcat.
I precise that the binary of the programm can be on the remote computer, but it would be great if there is a way to execute it as a "real" remote programm, without need to get the executable on the remote machine.
First of all, your terminology is a bit off. You said you write a tcp client. But it seems you wrote a server. Because this programs should receive incoming tcp connection and request to then send responses.
In order to execute commands, you can use the exec* syscalls.
But then you would need to have the executables available in the machine.
Then you would need to build some for for loop around the tcp read that execute things for each line send, and a bit of setup to ensure that you redirect the output in the tcp connection. See the dupsyscall.
Ultimately, if you do not want to write a full shell-like program, you could just execthe system shell (cmd.exe on windows I think), and redirect all inputs/output to it.
I'm working on a project where I need to establish connection between my computer and a Adafruit feather 32u4 with BLE incorporated.
Due to comments on lots of webs, I decided to use linux to do the job.
I got everything installed and I can connect my BLE with the PC successfully.
----MY CONNECTION PROCEDURE-----
I can even recieve data and send data between them with gatttool.
To connect both devices i use this commands:
sudo hcitool lescan
sudo gatttool -t random -b F6:E5:F4:A7:71:E6 -I
connect
The devices are connected correctly. I can use all the gatttool commands and they respond as expected.
----END OF CONNECTION PROCEDURE----
---MAIN PROBLEM---
I don't know how I could implement all the commands in a packed C program.
I need to be able to manage all the commands in the same program !! without using brute force with system().
It would be great if someone could show me how gatttool do its magic.
I mainly need to know how to get the data from Rx and how to send it to Tx via code not commands.
Note: I can supply any further information if needed.
I am working on a line-oriented telnet server, not a client.
Currently, to set up the connection, I am using:
IAC DONT ECHO
IAC DONT SURPRESS-GO-AHEAD
IAC DO LINEMODE
IAC DO NAWS
Currently, the server only handles IAC AYT, and NAWS-related stuff. Anything else is rejected, like so:
IAC DONT <OPTION>
However, the server still gets characters one-at-a-time.
According to here, ECHO and SGA (at the same time) enable character-at-a-time mode. However, I have both disabled.
How can I make the client send data one line at a time?
I am using the telnet from GNU inetutils to test this.
This question's title is similar but, contrary to its title, concerns writing a telnet client.
I just checked my old telnet server source and I send WILL and WONT from the server side. I handled DO and DONT from the client.
Are you actually trying to code a true telnet server, or just a server that is compatible with telnet that does sends data a line at a time (like a text based chat or game server)? If the latter, you can do away with most of your options because in my experience, telnet clients default to line at a time.
For my game server (MUD++) all I ever did in standard game play mode was to disable / enable echo during password state in login, or kick into character mode and start a pseudo tty when the user invoked the PICO editor.
UPDATE: If you plan to seriously write a telnet server or any other network software, I really like the classic W. Richard Stevens series. TCP/IP Illustrated Volume 1, The Protocols covers telnet in a practical sense, and coupled with the RFCs like 1184 (if I recall) you'll have everything you need.
I'm trying to learn how to write C code that will read from the serial port in Linux. I've found what seems to be a good tutorial here.
I want to be able to test this code, so I think I need either a serial port, or a way to write to the serial port while the code from above is reading.
I'm running Ubuntu 10.04 as a virtual machine on my Mac using virtualbox. My idea was to set up a virtual serial connection and write from the host to the guest. Hopefully something as simple as cat "Hello World" > /tmp/fake_serial in a host terminal, and for that to be read by the program in the link above.
Is this possible? I've tried adding a serial port using virtual box and when I try to do the above command I get an error saying I can't write to a socket.
The second option I thought of was using something like minicom inside the guest OS, to connect to say /dev/ttyS1 and write messages for my code to read at the same time. Again, assuming that the baud rates and other settings are OK, would this be possible?
I don't have a lot of experience working with serial ports, so I'd appreciate any suggestions about the best way to do this. Thanks in advance.
So to get this working I just added another Ubuntu VM on VirtualBox, and connected the two together via a virtual serial port. My main, original VM, which I use for a lot of developing will be referred to as VM1. The new VM, with a small hardrive that will only be used for sending messages to VM1 will be called VM2. These are both Ubuntu 10.04 VMs.
In VirtualBox go to Settings for VM1, go to ports, and change the settings as follows:
Now go to VM2, and select settings, ports, then change as follows:
Now first you need to start VM1. When that's booted then boot VM2. Now you can open a terminal in VM1, and type screen /dev/ttyS0 38400 (you may need to run sudo apt-get install screen before this works). Then go to VM2, open a terminal, and type echo "Hello" > /dev/ttyS0.
You should see Hello appear in the terminal open in VM1. When you're done running screen press ctrl-a k to kill it, otherwise if you try to do other stuff with the serial port you may get an error message saying that the port is busy.
When I had to do some serial port testing from my real to virtual machine I ended up doing a "loop back" type testing. I took two USB-Serial converters and a RS232 F-F adaptor and connected my machine to itself. Then in VirtualBox under Settings->USB you can route one of the two USB-Serial converters to be "owned" by your VirtualBox.
Once you plug in the converters one will register with the Mac and one with the Ubuntu "computer" then you can do serial communication as normal between the two machines.
You may also be able to emulate a virtual serial port using a pty ("pseudo-teletype" device), but I'm not positive on that one since I believe the ability to do that was locked down in newer kernels.
I ran into a similar situation running a QNX guest using VirtualBox 5.0.10 on an Ubuntu 14.04 host.
My solution seems general enough to apply to the above-mentioned case.
I configured the guest VM in the same way that Kells1986 setup his VM1:
Under the "Serial Ports"/"Port1" tab:
check "Enable Serial Port"
set "Port Number" to "COM1"
set "IRQ" to "4"
set "I/O Port" to "0x3F8"
set "Port Mode" to "Host Pipe"
uncheck "Connect to existing pipe/socket"
set "Path/Address" to an accessible file-system path (e.g. "/home/safayet/vmSerialPipe")
According to the VirtualBox manual:
You can tell VirtualBox to connect the virtual serial port to a
software pipe on the host. ... On a Mac, Linux or Solaris host, a local domain socket is used ... On Linux there are various tools which can connect to a local domain socket or create one in server mode. The most flexible tool is socat and is available as part of many distributions.
A domain socket is an IPC mechanism on UNIX systems similar to a pipe.
I connected to the "pipe" end of the virtual serial port on the Ubuntu host using the socat command:
socat - UNIX-CONNECT:/home/safayet/vmSerialPipe
I wanna use a TUI over telnet connection between two Linux boxes like ncurses, is there a way to do this or to use TUIs through telnet in C?
Do you mean you want to telnet to a server machine and run an ncurses application, or do you somehow want to run a UI on one machine, and a backend on the other. If it's the former, you just need to set the TERM environment variable correctly on the server machine before running your program (i.e., export TERM=vt100).
If it's the latter, then ncurses itself isn't going to do any networking, but you could certainly write a client that uses ncurses, and have the client talk to a server backend in some way.