Click to See Complete Forum and Search --> : RE: Remote control ports over internet


kestral
09-11-2001, 10:10 AM
hi,

I have written a CGI script to allow me to input values to outb(v,0x378) to my printer ports to do a simple control of LED by lighting up the respective lights. But after debugging for quite some time, I still can't find the source of my problem. Hope u can help :) thanks


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/io.h>
#include "cgi-util.h"

#define BASEPORT 0x378 /* lp1 */

/* --- MAIN --- */

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


/* Initialize the CGI and send out an HTTP header: */

res = cgi_init();

printf("Content-type: text/html\n\n");


/* Was there an error initializing the CGI??? */

if (res != CGIERR_NONE)
{
printf("Error # %d: %s<p>\n", res, cgi_strerror(res));
exit(0);
}


/* Display some text: */

printf("Hello.<p>\n");


/* Grab some fields from an HTML form and display them: */

if (cgi_getentrystr("name") != NULL)
printf("name=%s<p>\n", cgi_getentrystr("name"));

printf("age=%d<p>\n", cgi_getentryint("age"));

if (cgi_getentrystr("sex") != NULL)
printf("sex=%s<p>\n", cgi_getentrystr("sex"));


v = cgi_getentryint("lamp");

printf("lamp=%d is on<p>\n", v);


/* Get access to the ports */
if (ioperm(BASEPORT, 1, 1))
{
perror("ioperm");
exit(1);
}

/* Set the data signals */

outb(v, BASEPORT);

/* We don't need the ports anymore */

if (ioperm(BASEPORT, 1, 0))
{
perror("ioperm");
exit(1);
}


/* Close up the CGI: */

printf("Goodbye!<p>\n");

cgi_quit();

return(0);
}