PDA

View Full Version : syn - syn/ack -rst


gerry
04-04-2003, 07:58 PM
Hi there,

I'm just starting with socket programming and I wanna make a program, that
looks for an open port on a given ip-address. That should be easy - I hoped ...

I wanna get a return message, if server and port is not accepting client calls.

First I tried it with "connect ()" . That works fine when the server has an open port and sends me an syn/ack - BUT : if the server does not send an syn/ack the connect () waits forever - sending a syn periodically. Is there a chance t set the timeout for connect () [e.g. setsockopt ()] ????

Second I tried raw IP. I send a syn-packet and waited for a syn/ack. Using sendto and recv. But I can only see my syn with tcpdump.

Maybe that everything is so easy - and I'm so fool - sorry I cannot get the stuff running.

Can somebody please give me sample-code or any hint ...


TIA
Gerry

:oops:

RobSeace
04-04-2003, 09:59 PM
If nothing is listening on the port, you should get a RST, and hence
the connect() should return immediately with failure... If it's waiting
for a long time and receiving no response at all to the SYN, then
either there's network trouble enroute to the destination, or the
destination host is dead, or there is some kind of firewall or something
dropping your SYNs on the floor, without generating a response of any
kind...

There's no native timeout method for connect()... It will timeout
eventually on its own when the TCP/IP stack gives up trying, but that
could take a while... If you want a sooner timeout, you have to do it
yourself the standard way: either use a blocking alarm()-based
timeout, or set the socket for non-blocking I/O and perform a
non-blocking connection, using select() to perform the timeout...
There are examples of both methods floating around the forum here,
somewhere... Here (http://www.developerweb.net/forum/viewtopic.php?t=80) is the main FAQ section on the topic, which has some
code for the blocking alarm()-based method, and descriptions of the
non-blocking method... (Though, I don't really care for that alarm()-based
code shown, either... It relies on the system not restarting syscalls,
which some of them like to do...) And, here (http://www.developerweb.net/forum/viewtopic.php?t=147) is some discussion and code
for a non-blocking connect()...