Thread: How to close an open port with WindowsSockets

  1. #1
    Registered User codingmaster's Avatar
    Join Date
    Sep 2002
    Posts
    309

    How to close an open port with WindowsSockets

    A friend of me is coding a sharing tool, Cshare.

    He and I wanna know how it works to close an open port (WindowsSockets), because it is dangerous to have an open port, that is not used by any prog, so you can be hacked or DOS attacked!!!

    He is coding in C

    I'm coding in C++

    OS: Win32
    Network: WindowsSockets

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Are you and your friend working on a firewall for Windows? One solution to close a port without going into detail about Windows security is to simply open a socket on that port and ignore all data.

    Kuphryn

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    The socket will not close if there is data incomming or it is 'held' open by the server.

    Try this, before calling to close, to slam the socket shut without waiting for it to clean up.
    Code:
    LINGER    DontLinger;
    
    DontLinger.l_onoff=1;
    DontLinger.l_linger=0;
    
    setsockopt(Socket, SOL_SOCKET, SO_LINGER  ,(char*)&DontLinger ,sizeof(LINGER) );
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User codingmaster's Avatar
    Join Date
    Sep 2002
    Posts
    309
    We aren't coding a firewall, he is gonna use it for sharing, like Napster, the prob was, that the port wasn't closed -> we gonna check it.

    Thank's for the help (-> but is there a function to close directly the port, when the tool is going to be closed).

    I think this information will help me too, for coding a Apache module for this sharing prog.


    cu, codingmaster
    Last edited by codingmaster; 10-02-2002 at 02:43 AM.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    You mean

    if(closesocket(SOCKET)==SOCKET_ERROR)
    iError=WSAGetLastError();
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. serial port to poll on request
    By infineonintern in forum C++ Programming
    Replies: 2
    Last Post: 06-11-2009, 06:52 AM
  2. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM
  3. Serial port read..can someone tell me..
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 06-27-2002, 08:21 AM
  4. Replies: 8
    Last Post: 11-21-2001, 12:13 AM
  5. Ghost in the CD Drive
    By Natase in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 10-12-2001, 05:38 PM