Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
作为服务器,有没有办法在收到来自客户端的消息后将客户端的 IP 地址作为字符串获取recvfrom()?我会假设它在sockaddr_in结构中,但我不知道如何访问它。谁能告诉我我该怎么做?
recvfrom()
sockaddr_in
IP 地址确实存储在struct sockaddr或struct sockaddr_in其地址被传递给recvfrom,并且(假设结构名为“ sender”)它可以转换为字符串:
struct sockaddr
struct sockaddr_in
recvfrom
sender
#include <arpa/inet.h> char* ipString = inet_ntoa(sender.sin_addr);