Telnet "wont echo" is supressed by windows machines [closed] - c

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
In my code for telnet client, I want to echo always. So I will send wont echo to the server.
Linux machines obey the command, but windows machines suppress the wont command and send do echo command instead [confirmed from wireshark and GDB].
What could be the possible reason?

If I understand correctly, WILL and WONT indicate the "local" state. If you want the other party to switch to another mode, you have to send a DO or DONT command.
So, I guess you have to sent a "WILL ECHO", and "DONT ECHO" (meaning: I will perform the echo, so you don't have to echo).
Maybe this document will help:
The Q Method of Implementing TELNET Option Negotiation: https://www.rfc-editor.org/rfc/rfc1143

In my code for telnet client, I want to echo always. So I will send wont echo to the server.
That's wrong for a start. If you will echo, you need to send DONT echo. WILL/WONT is a response, not a request. And in any case if you want to echo why would you say you won't? It doesn't make sense.
Linux machines obey the command
It's not a command, it's a request. The server is free to agree or disagree. If the server disagrees it will send you the opposite WILL/WONT response. If it agrees it will send you an agreeing WILL/WONT response.
but windows machines suppress the wont command and send do echo command instead [confirmed from wireshark and GDB].
That's what you want! You want to echo, and it is telling you to echo. You got it wrong in the protocol but the end result is exactly as you wished.
Note: to avoid loops, if the peer had already sent a WILL/WONT response before you sent your DO/DONT, it won't send you the same message after it receives yours, if it now agrees with you. This can happen when either side initially disagrees. Again see the Telnet RFCs. You particularly need to read the one about how to implement this feature ('Q method').

Related

Allowing linux firewall to receive packets for my code [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I wrote a c code for ping command and for some reason it doesn't receive any reply. I spent couple of days trying to find problem with the code, but later I have checked packet sending with wireshark. I found that the reply was send to me (the destination is unreachable, as it should be with destination IP I entered). In Internet I found that my firewall could cause this problem, but I didin't find any solution for it. So please help me, how can I add some kind of exeption for my firewall for the certain code? Thank you.
EDITED
The iptables output:
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Wireshark output:
17 0.641636029 192.168.0.134 192.168.0.1 ICMP 120 Destination unreachable (Port unreachable)
Also I probably made a mistake and the problem may be not in the receiving, but in sending packet
Try to check firewall using the following command iptables -L -n And provide output
Consider using some library like liboping or libping
Be aware that ping uses ICMP (see icmp(7)). Your program is likely to require root privilege. So you need to run it as root, or use setuid techniques.
Check systematically against failure every system call that you are using (see syscalls(2) for a list). Read errno(3) and use perror(3) (or strerror(errno)).
Use also strace(1) on your program to understand what system calls are done (and which one is failing).

Batch server ping and restart for a game

Just looking for a correction/addition to this cannibalized restart code for (originally a Minecraft server, though that is not what it's used for now).
#echo off
title Server Restarter
color 0A
cls
#%SystemRoot%\system32\ping.exe -n 1 xxx.xxx.x.xx
pause
:start
Call Server.bat
cls
pause
This currently does a very simple job: calls server.bat and starts the server. It has none of the bells and whistles I'd like it to have though.
The output of ping is not functional at the moment.
The goal:
Ping to see if a specific IP (and maybe ports) are reachable.
If they are not reachable, close any current instances of Server.exe
Continue pinging until specific IP is reachable.
Once the IP is reachable, call server.bat
It needs to ping at intervals of ~30 seconds.
Some context for why it's needed:
The game server does not currently close its process regardless of it being online or not, it continues to run in the process window. That's why I need it close any current instances, else we just end up with multiples of the same server running.
The server is run from a local computer using direct IP connection, therefore if the local computer isn't connected to the internet, the server wont be reachable to anyone (obviously). The intent for the .bat is to run continuously so even when the user isn't at the computer, it will take care of ensuring the server is online 24/7.
This will be a file I will want to make available to other server hosts who may want to use it to keep themselves online 24/7.
The port check will be to ensure the master server ports are reachable and the fault is/isn't on their side, this is not essential so if it's too much trouble, don't worry.
Inside "Server.bat":
#echo off
echo Server process starting
echo Ctrl+Alt+Del to Kill
Server.exe -batchmode -nographics
All of your assistance and comments are very much welcomed. I tried to generalize this as much as possible to keep it simple, so it can be altered for anyone else who may find use for it with any application.
Sounds like you're working on or with a Windows machine. Power Shell might be an option to write your scripts. I came across this question after investigating Test-Connection and Test-NetConnection, which are both kind of like ping, and the latter lets you test if a port is open. Not sure if there are batch file commands like those, but Power Shell lets you use most batch commands. Both of these commands have tons of examples online, and are very easy to use in your use-case.
You probably want to have a while (true) loop running, and periodically do your ping/port checks. That will satisfy your continual checking requirement. Start-Sleep is a cmdlet to let you pause your script, which you'll want to do in your forever loop.
You can call batch files from Power Shell (another link from another good resource), so that will let you reuse your existing scripts if you don't want to rewrite them in Power Shell.

Detecting network activity in C [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
If I lose connection to a server, I start an alarm to go off in 10 minutes. In the meantime I try to create a socket and re-establish a connection to the server. If when the alarm goes off, there is no connection to the server, I want to close the application.
What would be a good way to go about checking if there is a live connection on a socket? I am unsure if blocking methods are acceptable (obviously if there is no alternative they are).
If I lose connection to a server, I start an alarm to go off in 10 minutes.
So at that point you knew there was no connection.
In the meantime I try to create a socket and re-establish a connection to the server. If when the alarm goes off, there is no connection to the server, I want to close the application.
What would be a good way to go about checking if there is a live connection on a socket? I am unsure if blocking methods are acceptable (obviously if there is no alternative they are).
If you knew there was no connection when you set the alarm, why don't you know the same thing when it expires?
It seems to me that all you need to do is examine the socket fd. If it is non-zero you have a connection; if it is zero you don't. And make sure you zero it when you set the alarm.
Just save a result of "connect()" function anywhere, so you will be able to check it in 10 minutes.
What would be a good way to go about checking if there is a live connection on a socket? I am unsure if blocking methods are acceptable (obviously if there is no alternative they are).
I Assume from this question end the explanation above that you have the idea how to handle a lost connection but don't know how to check if the connection is still alive.
Best way to check if the connection is still alive is to send periodically a dummy / heartbeat / keep-alive message to the server. As soon as the connection is dead the tcp socket will give you an error (after the timeout) so you know that the connection died and you can try to reconnect / flag the alarm etc.

Recovering from ipconfig /release on a remote PC [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Not strictly a programming question, but I was programming at the time and couldn't find an answer, so I thought, "Hey, I'll give StackOverflow a try!"
So I'm connected to my Windows XP work PC over a Remote Desktop connection through VPN. In a command window (on the remote PC), I foolishly type ipconfig /release. A split second before I come to my senses, I hit Enter. D'oh!
So what now? Am I hosed until I get to the office Monday morning? Any way to remotely make my office PC get itself a new IP address?
If it makes you feel any better, most of us have done something similar. I can't offer a suggestion that doesn't involve human intervention, but I can offer two ways to prevent a "next time" for you:
Look into a remote power controller. Cheap (inexpensive, hobbyist-grade) options are available through www.x10.com; other vendors (Pulizzi, DataProbe, etc.) provide more reliable solutions for a higher price. You may even be able to find a UPS that allows you to control it via a serial port.
Plug your PC into the power controller, and find a second PC to control it. Now you can reboot your PC remotely, no matter how badly you de-configure it.
Anticipate and compensate. It's reasonable to expect that you may need to release/renew the IP address again, so write a utility that will check for the loss of IP address and reboot if that occurs. For example, ping your default gateway and reboot if the ping fails consistently. Just be sure to anticipate the consequences of an unexpected reboot!
Try giving a call to the office and get someone(if any) to restart your computer or ipconfig /renew
What you need to do, is find some way to cut the power to your PC. Many PCs are configured by default to reboot if there is a power failure. So, just hack into your power grid, and shut off power to the entire building. Once your computer reboots, along with all the other equipment, your computer should have it's IP back.
(This probably won't work)
I think if you get your network connection severed, it'll reset (like, if I run ipconfig /release, then shut off my router and restart it, I get a new IP).
It'd be well winging it, but if I was desperate I'd hook up to my DHCP server and reboot it.. I predict the end result would be me still not being able to connect, and the admins giving me a good whipping.
Log into the managed switch the PC is connected to, shutdown the port, wait a few seconds, and then bring it back up. If you don't have a managed switch or no access to it, wait until Monday.

Local Chat server in C using IPC

Hi Guys I need to write a chat server in C. It only needs to use IPC.
Could you help me on how to proceed on this. A skeleton code will help me a lot.
Write an echo server: a server that accepts one client, and repeats everything the client says back to it.
Expand this server to support multiple simultaneous connections.
Have the server echo to all connections.
Consider as commands some pattern of lines from clients -- an initial "/", say, and act on them (close the connection, name the connection, list connections, etc.) rather than echo them.
Prefix all echo'd text with the name of the client, with a default "Anonymous$N" and then the name set by a command from #4.
When receiving a new connection, have the server elicit a name from it before the server begins echoing text from it and acting on other commands.
And so on. As mentioned, Beej's Guide can help you get past #1 and #2.
EDIT: OK, you added the 'IPC' language. You can still use sockets for this over the loopback device, unless you've some special requirement that you think IPC covers. You can also use UNIX domain sockets - named pipes. perlipc discusses them with a short example, and you can continue to e.g. the GNU C library manual.

Resources