Continuity

 view release on metacpan or  search on metacpan

util/highport.c  view on Meta::CPAN


/*

  Turns CGI hits back into HTTP hits to transparently proxy hits on a
  main Webserver into hits on a high-port application process with its
  own Webserver.  More generally, it adds proxying capabilities to Webserver
  such as thttpd that lack the feature natively.

  This version is incomplete with regards to the headers it sends.  It's
  also woefully lacking in the options department.

  There's dead code that should be removed.

  There are probably better versions of this same thing floating around.

  Scott Walters, 200604, scott@slowass.net

 */

#include <unistd.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>

extern int errno;
int s;
int errlog;

int
main(int argc, char *argv[]) {

    int port;
    char buf[8192];
    struct sockaddr_in peer;
    fd_set rfds, efds;
    struct timeval tv;
    int err;
    int errlen = sizeof(err);
    int line_skipped = 0;
    int zero_bytes_in_row = 0;
    int zero_bytes_in_row_in = 0;
    char * query_string;

    // http://cgi-spec.golux.com/draft-coar-cgi-v11-03.html
    if(argc < 2) exit(1);
    port = atoi(argv[1]);

    peer.sin_family       = AF_INET;
    peer.sin_addr.s_addr  = inet_addr("127.0.0.1");
    peer.sin_port         = htons(port);

    s = socket( AF_INET, SOCK_STREAM, 0 );
    if(!s) exit(2);

    // errlog = open("/tmp/highport.log", O_WRONLY|O_CREAT);

    if ( connect( s, ( struct sockaddr * )&peer, sizeof( peer ) ) ) {
        perror("socket connect failed");



( run in 2.608 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )