I'm calling gethostbyname() giving as parameter an MX record but it is allways NULL...
The code below, given a mail, checks the MX record of that provider and tryes to retrieve the IP address... but it fails while calling gethostbyname()
the output is:Code:int getMX(char* email) { char* dominio; struct hostent *host; DNS_RECORD* pRecordList = NULL; DNS_RECORD* pRecord = NULL; dominio = strtok (email, "@"); dominio = strtok (NULL, "@"); /* Send the DNS query... */ if (NOERROR == DnsQuery_A(dominio, DNS_TYPE_MX, DNS_QUERY_STANDARD, NULL, &pRecordList, NULL)) { // get the first MX record for (pRecord = pRecordList; pRecord != NULL; pRecord = pRecord->pNext) { if (pRecord->wType == DNS_TYPE_MX) { printf("-> MX Server: %s\n", (char*)pRecord->Data.MX.pNameExchange); // try to resolve it if ((host = gethostbyname((char*)pRecord->Data.MX.pNameExchange)) != NULL){ printf(" Host: %s\n", host->h_name); } else printf("Unable to resolve the IP.\n"); } else printf("-> MX Server NOT FOUND\n"); break; } DnsRecordListFree(pRecordList, DnsFreeRecordList); return 0; } else { printf("-> Unreachable.\n"); return -1; } }



LinkBack URL
About LinkBacks




