- #include <windows.h>
- #include <winsock.h>
-
- #define C_BON 1
-
- #define ERR_CONNECT 10
- #define ERR_CREATION_SOCKET 17
-
- int Connection(SOCKET *s, SOCKADDR_IN *info, char adresse[], int port, unsigned int msg, HWND Hwnd) {
- int err;
- struct hostent *host;
-
- info->sin_family = PF_INET;
- info->sin_port = htons(port);
- info->sin_addr.s_addr = inet_addr(adresse);
-
- if (info->sin_addr.s_addr = -1)
- { host = gethostbyname(adresse);
- memcpy((char *)&info->sin_addr.s_addr, host->h_addr, host->h_length);
- }
- if ((*s = socket(PF_INET, SOCK_STREAM, 0)) == -1)
- {
- return ERR_CREATION_SOCKET;
- }
- if ((err = connect(*s, (struct sockaddr *)info, sizeof(*info))) == -1)
- {
- return ERR_CONNECT;
- } else
- {
- WSAAsyncSelect(*s , Hwnd, msg, FD_READ);
- return C_BON;
- }
- }
#include <windows.h>
#include <winsock.h>
#define C_BON 1
#define ERR_CONNECT 10
#define ERR_CREATION_SOCKET 17
int Connection(SOCKET *s, SOCKADDR_IN *info, char adresse[], int port, unsigned int msg, HWND Hwnd) {
int err;
struct hostent *host;
info->sin_family = PF_INET;
info->sin_port = htons(port);
info->sin_addr.s_addr = inet_addr(adresse);
if (info->sin_addr.s_addr = -1)
{ host = gethostbyname(adresse);
memcpy((char *)&info->sin_addr.s_addr, host->h_addr, host->h_length);
}
if ((*s = socket(PF_INET, SOCK_STREAM, 0)) == -1)
{
return ERR_CREATION_SOCKET;
}
if ((err = connect(*s, (struct sockaddr *)info, sizeof(*info))) == -1)
{
return ERR_CONNECT;
} else
{
WSAAsyncSelect(*s , Hwnd, msg, FD_READ);
return C_BON;
}
}