我的服务器程序在某个TCP端口监听连接,我想拒绝部分IP的连接,
现在我的做法是accept以后分析其IP,如果是目标IP则closesocket
有可能在accept之前拒绝吗?

解决方案 »

  1.   

    你的做法是正确的,没有办法在accept之前拒绝
      

  2.   

    tcp是知道的,但berkley不给用户机会判断。抱怨已经很多了。
      

  3.   

    SOCKET WSAAccept(
      SOCKET s,
      struct sockaddr* addr,
      LPINT addrlen,
      LPCONDITIONPROC lpfnCondition,
      DWORD dwCallbackData
    );lpfnCondition 
    [in] Procedure instance address of the optional, application-specified condition function that will make an accept/reject decision based on the caller information passed in as parameters, and optionally create or join a socket group by assigning an appropriate value to the result parameter g of this function