I tried to create a UDP socket on mingw, but socket()
returns -1
, with errno = 0
. Strange.
I have included winsock2.h.
Initially I had compilation error undefined reference to socket@12
, after setting
-lws2_32
and -lwsock32
to Linker Settings of Code::Block, compilation success.
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
RDF_LOG(kDEBUG, "sockfd %d ", sockfd);
if (sockfd < 0){
RDF_LOG(kERROR, "ERROR: %s , errno %d\n", strerror(errno), errno);
}
Result --> sockfd -1 ERROR: No error , errno 0
OK, I change RDF_LOG to fprintf instead.
int tmp = 0;
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
tmp = errno;
fprintf(stderr, "sockfd %d ", sockfd);
if (sockfd < 0){
fprintf(stderr, "socket: %s , errno %d\n", strerror(tmp), tmp);
}
The result returned is, still, --> sockfd -1 socket: No error , errno 0 Is it possible that mingw does not support errno??