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

inb.cc

Go to the documentation of this file.
00001 /*
00002   inb.c
00003 
00004   Reports value of a x86 hardware port register.
00005   Parse command line, call inb(), 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("inb 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(), inb 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>\n");
00043       exit(-1);
00044     }
00045 
00046   port = strtoul(argv[1],NULL,0);
00047   if(geteuid() && getuid())
00048     {
00049       printf("Must be root for this program to work.\n");
00050       exit(-1);
00051     }
00052 
00053   if(-1 == iopl(3))
00054     {
00055       printf("Can't set privaledge level.\n");
00056     }
00057   val = inb(port);
00058   printf("0x%X\n",val);
00059   exit(0);
00060 
00061 }
00062 #endif

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