Alright.
Brief description of problem:
I am running a tiny C program to control the output on the parallel port. It runs on some machines, but on others, I get a Segmentation Fault.
Full Description:
I have a problem with my DSL line going down, so I used the coffee how-to and some other sites to construct a circuit that hooks up to the parallel port and drives a relay to cut power to the dsl modem. I am using a very tiny C program listed below.
I tested the program and circuit on a laptop under RedHat8 and it works perfectly. However when I compile and run the C program on either of two desktops running RedHat9 it exits with a Segmentation Fault. I need help in getting this to work.
Here is the Kernel Message defining the parallel port:
Jun 27 07:09:50 ksix kernel: parport0: PC-style at 0x378 (0x778) [PCSPP,TRISTATE]
Jun 27 07:09:51 ksix kernel: parport0: irq 7 detected
Here is the C program:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <asm/io.h>
#define base 0x378 /* printer port base address */
main(int argc, char **argv)
{
int value;
if (argc!=2)
fprintf(stderr, "Error: Wrong number of arguments. This program needs one argument which is number between 0 and 255.\n"), exit(1);
if (sscanf(argv[1],"%i",&value)!=1)
fprintf(stderr, "Error: Parameter is not a number.\n"), exit(1);
if ((value<0) || (value>255))
fprintf(stderr, "Error: Invalid numeric value. The parameter number must be between 0 and 255\n"), exit(1);
if (ioperm(base,1,1))
fprintf(stderr, "Error: Couldn't get the port at %x\n", base), exit(1);
outb((unsigned char)value, base);
}