Skip to content

Instantly share code, notes, and snippets.

@matwey
Last active January 29, 2020 23:04
Show Gist options
  • Save matwey/b42f8b9fb50ab8c603d120c54d04c9be to your computer and use it in GitHub Desktop.
Save matwey/b42f8b9fb50ab8c603d120c54d04c9be to your computer and use it in GitHub Desktop.
read /dev/port
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
int main(int argc, char** argv) {
int fd;
off_t ret;
ssize_t ret2;
unsigned char buf[64];
int i;
fd = open("/dev/port", O_RDWR);
if (fd < 0) {
perror("open");
return 1;
}
ret = lseek(fd, 0xe100, SEEK_SET);
if (ret == (off_t)-1) {
perror("lseek");
return 1;
}
ret2 = read(fd, buf, sizeof(buf));
if (ret2 < 0) {
perror("read");
return 1;
}
printf("%d: ", ret2);
for (i=0;i<ret2;i++) {
printf("%02x ", buf[i]);
}
printf("\n");
close(fd);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment