Your addr
variable is declared as a sockaddr
. It needs to be declared as a sockaddr_in
(works with IPv4 only) or SOCKADDR_STORAGE
(works with both IPv4 and IPv6), and then typecast it to sockaddr*
when passing it to recvfrom()
.
Aside from that, you say that recvfrom()
is not returning >= 0. So what is it actually returning? If it returns 0, then a 0-length packet was received (impossible for TCP, but possible for UDP). If it returns -1 (aka SOCKET_ERROR
), then an error occured so use WSAGetLastError()
to find out what that error actually is.