static char i_host[MAX_STRING_LEN]; /* site name the web cache sitting in */
static char i_port[MAX_STRING_LEN]; /* port number invalidator listens on */
static char i_pass[MAX_STRING_LEN]; /* password of user invalidator */
static char i_uriprefix[MAX_STRING_LEN]; /* Specify the prefix path of the documents to be invalidated. The prefix path must begin with http|https://host_name:port/path/filename or "/" and end with "/". */
static char i_uri[MAX_STRING_LEN]; /* Specify the URL of the documents to be invalidated underneath the URIPREFIX */
static int i_verbose = 1;
int tcp_connect(const char *host, const unsigned short port)
{
char * transport = "tcp";
struct hostent *phe; /* pointer to host information entry */
struct protoent *ppe; /* pointer to protocol information entry*/
struct sockaddr_in sin; /* an Internet endpoint address */
int s; /* socket descriptor and socket type */
#ifdef WIN32
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 0 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
/* Tell the user that we couldn't find a usable */
/* WinSock DLL. */
printf("can't initialize socket library\n");
exit(0);
}
}
#endif
if ((sin.sin_port = htons(port)) == 0)
err_quit("invalid port \"%d\"\n", port);
/* Map host name to IP address, allowing for dotted decimal */
if ( phe = gethostbyname(host) )
memcpy(&sin.sin_addr, phe->h_addr, phe->h_length);
else if ( (sin.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE )
err_quit("can't get \"%s\" host entry\n", host);
/* Map transport protocol name to protocol number */
if ( (ppe = getprotobyname(transport)) == 0)
err_quit("can't get \"%s\" protocol entry\n", transport);
/* Allocate a socket */
s = socket(PF_INET, SOCK_STREAM, ppe->p_proto);
if (s < 0)
err_quit("can't create socket: %s\n", strerror(errno));
/* Connect the socket */
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0)
err_quit("can't connect to %s:%d\n", host, port);
return s;
}