Oracle iPlanet Web Proxy Server 4.0.14 Configuration File Reference

Example

This example uses the native connect mechanism to establish the connection:


#include "base/session.h"
#include "frame/req.h"
#include <ctype.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
int my_connect_func(pblock *pb, Session *sn, Request *rq)
{

    struct sockaddr_in sa;
    int sd;
    memset(&sa, 0, sizeof(sa));
    sa.sin_family = AF_INET;
    sa.sin_port   = htons(atoi (pblock_findval (“connect-port”, rq->vars)));
    /* host name resolution */
    if (isdigit(*pblock_findval (“connect-host”, rq->vars)))
        sa.sin_addr.s_addr = inet_addr(rq->host);
    else
     {
        struct hostent *hp = servact_gethostbyname(pblock_findval 
			(“connect-host”, rq->vars), sn, rq));
        if (!hp)
            return REQ_ABORTED;                         /* can’t resolv */
        memcpy(&sa.sin_addr, hp->h_addr, hp->h_lenght);
    }
    /* create the socket and connect */
sd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (sd == -1)
        return REQ_ABORTED;                      /* can’t create socket */
    if (connect(sd, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
        close(sd);
            return REQ_ABORTED;                      /* can’t connect */
    }
    return sd;                                 /* ok */
}