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:

Uzume
04-06-2003, 12:45 AM
You can implement a timeout on connect() using non-blocking sockets and select() with a timeout.

If you look about the net you should find various implementations of this since this is a well known-problem.

As for the raw socket stuff, this sort of thing is highly system specific and not all systems do it the same. There are a number of portable libraries that attempt to do this sort of thing portably. I recommend if you go this route to use one of those and save yourself the grief of trying to make this work yourself (who wants to reinvent the wheel?).