All pastes #346 Raw Edit

loghit.c

public c v1 · immutable
#346 ·published 2004-07-29 00:31 UTC
rendered paste body
#include "mod_pstats.h"int log_hit(request_rec *r, time_t now, time_t firsthit, time_t lasthit, char *ip, char *useragent, char *session, char *query) {  struct sockaddr_in sai;  int s, i;  s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);  if(s == -1) return log_file_hit(r, now, firsthit, lasthit, ip, useragent, session, query);  sai.sin_family      = AF_INET;  sai.sin_addr.s_addr = inet_addr("127.0.0.1");  sai.sin_port        = htons(PSTATS_PORT);  if(connect(s, (struct sockaddr *)&sai, sizeof(sai)) == -1)    return log_file_hit(r, now, firsthit, lasthit, ip, useragent, session, query);  send(s, (char *)&now,      sizeof(now),      0);  send(s, (char *)&firsthit, sizeof(firsthit), 0);  send(s, (char *)&lasthit,  sizeof(lasthit),  0);  i = pr_strlen(ip);  send(s, (char *)&i,        sizeof(i),        0);  send(s, (char *)ip,        i,                0);  i = pr_strlen(useragent);  send(s, (char *)&i,        sizeof(i),        0);  send(s, (char *)useragent, i,                0);  i = pr_strlen(session);  send(s, (char *)&i,        sizeof(i),        0);  send(s, (char *)session,   i,                0);  i = pr_strlen(query);  send(s, (char *)&i,        sizeof(i),        0);  send(s, (char *)query,     i,                0);  close(s);  return 0;}