Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

outb.cc

Go to the documentation of this file.
00001 /*
00002   outb.c
00003 
00004   Set the value  of a x86 hardware port register.
00005   Parse command line, call outb(), and print result.
00006 
00007    Modification History:
00008 
00009    13-Jan-2000 WPS created.
00010 */
00011 
00012 
00013 #ifndef linux
00014 
00015 #include <stdio.h>
00016 #include <stdlib.h>
00017 
00018 int main()
00019 {
00020   printf("outb doesn't work on this platform.\n");
00021   exit(-1);
00022 }
00023 
00024 #else
00025 
00026 #include <unistd.h>
00027 #include <sys/io.h>             // ioperm(), outb, inw outw
00028 #include <sys/types.h>
00029 #include <stdio.h>
00030 #include <string.h>
00031 #include <stdlib.h>
00032 #include <signal.h>
00033 
00034 
00035 int main(int argc, char **argv)
00036 {
00037   unsigned long port;
00038   char val;
00039 
00040   if(argc < 2)
00041     {
00042       printf("usage: <port> <value>\n");
00043       exit(-1);
00044     }
00045 
00046   port = strtoul(argv[1],NULL,0);
00047   val = (char) strtol(argv[2],NULL,0);
00048   if(geteuid() && getuid())
00049     {
00050       printf("Must be root for this program to work.\n");
00051       exit(-1);
00052     }
00053 
00054   if(-1 == iopl(3))
00055     {
00056       printf("Can't set privaledge level.\n");
00057     }
00058   outb(port,val);
00059 }
00060 #endif

Generated on Sun Dec 2 15:27:41 2001 for EMC by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001