Hi, everybody I understand winsock has gethostbyname for this. But I need to debug for embedded application and first I try the code on Windows. Here is a my code:
sockaddr\_in dns\_addr;
int dns\_size = sizeof(dns\_addr);
ZeroMemory(&dns\_addr, dns\_size);
dns\_addr.sin\_family = AF\_INET;
dns\_addr.sin\_port = htons(53);
dns\_addr.sin\_addr.s\_addr = inet\_addr("8.8.8.8");
SOCKET out = socket(AF\_INET, SOCK\_DGRAM, 0);
char msg\[\] = {
0x12, 0x34, // ID
0x01, 0x00, // QR ... RCODE
0x00, 0x01, // QDCOUNT
0x00, 0x00, // ANCOUNT
0x00, 0x00, // NSCOUNT
0x00, 0x00, // ARCOUNT
0x03,
0x77, 0x77, 0x77, // www
0x03,
0x74, 0x75, 0x74, // tut
0x02,
0x62, 0x79, // by
0x00,
0x00, 0x01, // TYPE\_A
0x00, 0x01 // CLASS\_IN
};
int msg\_size = sizeof(msg);
int iSendOk = sendto(out, msg, msg\_size, 0, (sockaddr\*)&dns\_addr, dns\_size);
if (iSendOk != SOCKET\_ERROR)
{
char bufstr\[100\];
sockaddr\_in dest\_addr;
int dest\_addr\_size = sizeof(dest\_addr);
int iReceived = recvfrom(out, bufstr, 100, 0,(sockaddr\*)&dest\_addr, &dest\_addr\_size);
}
closesocket(out);
And this code freezes when recvfrom function is execution. The function is executed with an infinite loop and never returns. What do I do wrong?
Eugene Pustovoyt Soft and Hard Developer CPPMessageBox v1.0 CPPToolTip v2.1 CPPDumpCtrl v1.2 CPPHtmlStatic v1.2