LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-07-2003, 06:01 PM   #1
GridX
LQ Newbie
 
Registered: Sep 2003
Location: Canada
Distribution: Fedora & Gentoo-uClinux
Posts: 15

Rep: Reputation: 0
http& c programming help


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, &gtime, 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(&gtime));
	     /*   shutdown(SockConnect,SHUT_RDWR);  close socket*/
		close (SockConnect);
	
		return 0;

}
note: the printf up in the code should read: printf("%s",ctime(&gtime)); 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

Last edited by GridX; 12-07-2003 at 06:04 PM.
 
Old 12-07-2003, 09:41 PM   #2
Stack
Member
 
Registered: Oct 2003
Distribution: FreeBSD
Posts: 325

Rep: Reputation: 30
Why dont you just write the time to an html file and let the webserver handle the job of displaying the webpage?
 
Old 12-07-2003, 11:19 PM   #3
sashhoney
Member
 
Registered: Jul 2003
Distribution: Red Hat, Fedora, Debian
Posts: 85

Rep: Reputation: 15
well my suggestion would be to write a simple php code to execute ntime file using exec
also u have to modify the c code to return the output rather than displaying using printf

ur c code
>return (ctime(&gtime))l;

ur php code
>exec(ntime,$time);
now $time will have the returned string,
 
Old 12-08-2003, 08:56 AM   #4
GridX
LQ Newbie
 
Registered: Sep 2003
Location: Canada
Distribution: Fedora & Gentoo-uClinux
Posts: 15

Original Poster
Rep: Reputation: 0
actually thats how I want to do it, to output html when I type the command at the address bar ie <ip address> /?ntime

that will out put the time on my html page..... but the out put must be in html format and I was told all I had to do is put the html code inside the printf statement. just dont know how to do it, cant really test it right now cause the code is for the dragon ball processor, and I have been having tourble connecting the microprocessor to my computer

GridX
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between Top Down programming & Bottom up programming minil Programming 1 06-17-2005 02:42 AM
SSH & HTTP port share possible? zahoo Linux - Networking 2 02-15-2005 08:43 PM
http protocol/programming advice... Scrag Programming 2 06-20-2004 10:00 PM
HTTP Interface Programming Nauseous Programming 1 08-04-2003 08:29 PM
http & ftp services jmono Linux - Newbie 5 05-08-2003 10:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration