/* * Create and write the log information to file * Log file format is one line per entry */ void log_line(char *req) { char log_buff[256]; char msg[1024]; char env_host[80], env_addr[80]; long addr; FILE *log; strcpy(log_buff,inet_ntoa(source.sin_addr)); sprintf(env_addr, "REMOTE_ADDR=%s",log_buff); addr=inet_addr(log_buff); strcpy(msg,adate()); strcat(msg," "); hst=gethostbyaddr((char*) &addr, 4, AF_INET); /* If DNS hostname exists */ if (hst) { strcat(msg,hst->h_name); sprintf(env_host, "REMOTE_HOST=%s",hst->h_name); } strcat(msg," ("); strcat(msg,log_buff); strcat(msg,") "); strcat(msg,req); if (daemonize) { log=fopen(logfile,"a"); fprintf(log,"%s\n",msg); fclose(log); } else printf("%s\n",msg); /* This is for CGI scripts */ putenv(env_addr); putenv(env_host); }
main() { printf("%s\n", adate()); }