initsockaddr.c (851B)
1 /************************************************************************* 2 * This file is part of Crosroads 1.23, a load balancer and fail over 3 * utility for TCP. Copyright (c) Karel Kubat, distributed under GPL. 4 * Visit http://crossroads.e-tunity.com for information. 5 *************************************************************************/ 6 #include "crossroads.h" 7 8 int init_sockaddr (struct sockaddr_in *name, 9 const char *hostname, int port) { 10 struct hostent *hostinfo; 11 12 if (program_stage != stage_retrying) 13 msg ("Service %s: trying to connect to backend %s:%d", 14 activeservice->name, hostname, port); 15 name->sin_family = AF_INET; 16 name->sin_port = htons (port); 17 if (! (hostinfo = gethostbyname (hostname)) ) 18 return (1); 19 name->sin_addr = *(struct in_addr *) hostinfo->h_addr; 20 return (0); 21 }