I have modified the httpd server file to execute a file by the ?argument
so I go to my browser i type in the ip address containig my web page, then at the end of the ip i put in the ? argument. or program to execute
so what I am doing is
http://<ip address>?ntime
ntime is the name of my argument or program, what it will do is display the current time on my web page (html format)
I have already written the socket code to obtain the time, now I am confused as to how to add the html in the printf to display to my web page in html format;
here is my code for ntime
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <netdb.h>
#include <time.h>
#define PORT 37
#define TIMEDIFF 2208988800UL
int main(int argc, char** argv)
{
time_t gtime;
struct sockaddr_in AddrServ;
int SockConnect;
int iSec =0;
if ( argc<3)
{
printf("Usuage: %s <IP Address of host>\n", argv[0]);
exit(EXIT_FAILURE);
}
/* create tcp socket to connect with*/
SockConnect = socket(AF_INET, SOCK_DGRAM,0);
if (SockConnect <0)
{
perror("Socket error: Unable to create");
exit(EXIT_FAILURE);
}
/* set up the serverr*/
AddrServ.sin_family = AF_INET; /*tcp/ip*/
AddrServ.sin_addr.s_addr =inet_addr(argv[1]);/*listen on all interfaces*/
AddrServ.sin_port = PORT; /*use port 37 to connect*/
memset(&AddrServ.sin_zero, '\0',8); /*zero padding*/
/*connect to server*/
if(sendto(SockConnect,0,0,0,(struct sockaddr*)&AddrServ,sizeof(AddrServ))<0)
{
perror("send error");
exit(EXIT_FAILURE);
}
recv(SockConnect, >ime, sizeof(gtime),0);
if(argc==3)
iSec=strtol(argv[2],(char**) NULL,10)*3600; /*use for m68k....(strtol)*/
gtime=gtime-TIMEDIFF; /* convert to 1970 formatting*/
gtime=gtime+iSec; /* to get current time*/
printf("%s",ctime(>ime));
/* shutdown(SockConnect,SHUT_RDWR); close socket*/
close (SockConnect);
return 0;
}
note: the printf up in the code should read: printf("%s",ctime(>ime)); just now sure how to modifiy it so it outputs the time to my web page, that is out puts the time in html format
any help would be great
GridX