Sunday, 15 February 2015

c++ - How to get the IP address of an incoming data packet on a DGRAM socket in WinSock2? -



c++ - How to get the IP address of an incoming data packet on a DGRAM socket in WinSock2? -

i doing work winsock , servers, , want ip address of client sending packet of info server.i prefer utilize sock_dgram-style sockets, using udp protocol. since not using sockets listen(), accept(), , connect(), , hence cannot utilize getpeername(), know how can information. short code snippet appreciated. also, right communicating on server on lan right now, need move farther out.

edit: far code goes, i'm not sure put.

i have socket sock_serv

it initialized so:

sock_serv = socket(af_inet, sock_dgram, ipproto_udp);

i recv()ing later on, after setting timeout. have confirmed timeout works, , can info recv don't know how sender.

use recvfrom. has output struct sockaddr parameter. http://msdn.microsoft.com/en-us/library/windows/desktop/ms740120(v=vs.85).aspx

c++ sockets winsock2

No comments:

Post a Comment