gethostbyaddr está bien en Windows pero devuelve NULL en Linux
Este fragmento de código funciona bien en Windows, pero gethostbyaddr devuelve NULL en Linux.
He intentado tantos cambios, pero sin ningún éxito.
Mi /etc/host.conf tiene la siguiente línea
ordenar hosts, enlazar
Ejecuto el código completo y paso la dirección 11.234.456.74, en windows gethostbyaddr resuelve la dirección y funciona bien. Sin embargo, en Linux no resuelve la dirección IP y devuelve NULL.
Por favor ayuda.
#ifdef WIN32
if (init){
WSADATA wsaData;
// Request Winsock version 2.2
if (WSAStartup (MAKEWORD(1, 1), &wsaData) != 0) {
WSACleanup();
exit (EXIT_FAILURE);
}
init = 0;
}
#endif
// Open required socket
p_socket[IP_SOCKET_SOCKET] = socket(AF_INET, server_socket_type, 0);
if ( p_socket[IP_SOCKET_SOCKET] < 0 ) {
#ifdef WIN32
WSACleanup();
#endif
exit (EXIT_FAILURE);
}
destAdrLen = mxGetM(prhs[0]) * mxGetN(prhs[0]) + 1;
destAdr = (char *) mxMalloc(destAdrLen);
if (destAdr == NULL) {
mexErrMsgTxt("mxMalloc(destAdrLen) failed");
}
mxGetString(prhs[0], destAdr, destAdrLen);
destPort = (int) mxGetScalar(prhs[1]);
if (isalpha(destAdr[0])) {
// socket address is a name
hp = gethostbyname(destAdr);
}
else {
// socket address is a number
addr = inet_addr(destAdr);
hp = gethostbyaddr((char *)&addr, 4, AF_INET);
}