Thread: weird problem

  1. #1
    Unregistered
    Guest

    Question weird problem

    i made a server for linux in C. when i port scan my computer it stops the server. can anyone please give me an example of some code to stop it port scanning fro mcrashing the server? thanks alot

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The reason it's stopping there is becaues your port scanner finds something on that port. You server is likely "blocking", and so it halts waiting for input from the connection it just got. You should set your server to use non-blocking mode.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    22

    weird problem

    I agree with Quzah. In addition if you really don't want your server to stop running just because of a port scan, you make it a system daemon using daemon(3) (man daemon). Then fork a child process to handle each connection that comes in. In that way, the main program (the daemon) will continue listening for connections i.e the port scan and other connections will be handled by child processes.
    -------------------------
    Gerald.

  4. #4
    The Artful Lurker Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    Consider using poll() to implement a timeout. Once accept() returns with the descriptor of the new connection, call poll() with a timeout of (for example) 15 seconds. If poll times out, you can simply close() the socket. If poll indicates there is data to be read (it did not time out), you can make your call to read()/recv().

    I urge you to review the poll man page.
    Jason Deckard

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird Problem With Pointer
    By DarkDot in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2007, 07:50 PM
  2. Weird problem on '02 3.4L V6 auto
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 01-12-2006, 12:05 AM
  3. Really Weird itoa Problem
    By Grantyt3 in forum C++ Programming
    Replies: 8
    Last Post: 12-20-2005, 12:44 AM
  4. Replies: 6
    Last Post: 05-12-2005, 03:39 AM
  5. Weird class problem!
    By aker_y3k in forum C++ Programming
    Replies: 2
    Last Post: 09-25-2002, 06:12 AM