int appIP::InitHost()
{
//creamos un socket para UDP
this->Socket=socket(AF_INET, SOCK_DGRAM, 0);
if (this->Socket==SOCKET_ERROR) return 1;
//limpiamos nuestra address para hacer de host
memset((void *)&Host, ' ', sizeof(struct sockaddr_in));
/* Set family and port */
Host.sin_family = AF_INET;
Host.sin_port = htons(Port);
/* Get host name of this computer */
gethostname(host_name, sizeof(host_name));
HostProperties = gethostbyname(host_name); //cojemos el nombre de la maquina local
/* Check for NULL pointer */
if (HostProperties == NULL)
return 1;
/* Assign the address */
Host.sin_addr.S_un.S_un_b.s_b1 = HostProperties->h_addr_list[0][0];
Host.sin_addr.S_un.S_un_b.s_b2 = HostProperties->h_addr_list[0][1];
Host.sin_addr.S_un.S_un_b.s_b3 = HostProperties->h_addr_list[0][2];
Host.sin_addr.S_un.S_un_b.s_b4 = HostProperties->h_addr_list[0][3];
/*tenemos la ip , hagamosla string*/
sprintf(StringIP,"%d.%d.%d.%d",Host.sin_addr.S_un.S_un_b.s_b1,Host.sin_addr.S_un.S_un_b.s_b2,Host.sin_addr.S_un.S_un_b.s_b3,Host.sin_addr.S_un.S_un_b.s_b4);
TimeOut.tv_usec = msTimeout%1000;
TimeOut.tv_sec = msTimeout/1000; // Time in seconds
FD_ZERO (&fdSocket);
FD_SET (Socket, &fdSocket); //ponemos el socket en vigilancia
if (bind(Socket, (struct sockaddr *)&Host, sizeof(struct sockaddr_in)) == -1)
{
return 1;
}
return 0;
}