Voici un bout de code des sources du logiciel VNC, la fonction connect(). Mon but est de réduire le temps de réponse (message:"failed to connect to server") si une IP n'est pas trouvée et pour l'instant je n'y arrive pas du tt ;-{ HELPPP!
void ClientConnection::Connect()
{
struct sockaddr_in thataddr;
int res;
m_sock = socket(PF_INET, SOCK_STREAM, 0);
if (m_sock == INVALID_SOCKET) throw WarningException(_T("Error creating socket"));
int one = 1;
// The host may be specified as a dotted address "a.b.c.d"
// Try that first
thataddr.sin_addr.s_addr = inet_addr(m_host);
// If it wasn't one of those, do gethostbyname
if (thataddr.sin_addr.s_addr == INADDR_NONE) {
LPHOSTENT lphost;
lphost = gethostbyname(m_host);
if (lphost == NULL) {
throw WarningException("Failed to get server address.\n\r"
"Did you type the host name correctly?");
};
thataddr.sin_addr.s_addr = ((LPIN_ADDR) lphost->h_addr)->s_addr;
};
thataddr.sin_family = AF_INET;
thataddr.sin_port = htons(m_port);
res = connect(m_sock, (LPSOCKADDR) &thataddr, sizeof(thataddr));
if (res == SOCKET_ERROR) throw WarningException("poste non connecté");
log.Print(0, _T("Connected to %s port %d\n"), m_host, m_port);
}