本文介绍了C++ Winsock API 如何在接受连接之前获取连接的客户端 IP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Winsock API(而不是 CAsyncSocket)来创建一个侦听传入连接的套接字.
I am using the Winsock API (not CAsyncSocket) to make a socket that listens for incoming connections.
当有人尝试连接时,我如何才能在接受连接之前获取他们的 IP 地址?我试图让它只接受来自某些 IP 地址的连接.
When somebody tries to connect, how can I get their IP address BEFORE accepting the connection? I am trying to make it only accept connections from certain IP addresses.
谢谢
推荐答案
SO_CONDITIONAL_ACCEPT 套接字选项.这里
SO_CONDITIONAL_ACCEPT socket option. Here
此外,很确定它可用于 XP 和 Server 2003,而不仅仅是 Vista.
Also, pretty sure it's available in XP and Server 2003, not just Vista.
这篇关于C++ Winsock API 如何在接受连接之前获取连接的客户端 IP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!