make getpeername() return the original socket address which before it was intercepted
[hband-tools.git] / compiled-tools / cdstatus.c
blob809294bedc349955edac58c64bb5825c5a3e7290
1 /* Begin C code. Put this in a file called cdstatus.c and do "gcc -o
2 * cdstatus cdstatus.c" . No error checking, no looping, no
3 * documentation, if it breaks, you get to keep both pieces. */
5 #include <stdio.h>
6 #include <fcntl.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <sys/ioctl.h>
10 #include <sys/wait.h>
11 #include <sys/mtio.h>
12 #include <linux/types.h>
13 #include <linux/cdrom.h>
15 int main(int argc, char **argv) {
16 char buff[256];
17 /* ioctl() needs a 3rd arg but it doesn't really use it here. */
18 int fd,status;
19 int ec=1;
21 if(argc!=2) {
22 fprintf(stderr,"Usage: cdstatus <CD-ROM device name>\n");
23 return 1;
26 fd=open(argv[1], O_RDONLY | O_NONBLOCK); /* need NONBLOCK! */
27 if(fd < 0) {
28 snprintf(buff,64,"%s cannot be opened\n",argv[1]);
29 perror(buff);
30 return 1;
32 status=ioctl(fd,CDROM_DRIVE_STATUS,buff);
33 close(fd);
35 switch(status) {
36 case CDS_NO_INFO:
37 printf("Whoa. Huh?");
38 ec=2;
39 break;
40 case CDS_NO_DISC:
41 printf("No disc is in the drive.");
42 ec=3;
43 break;
44 case CDS_TRAY_OPEN:
45 printf("Tray is open, or tray is closed and no CD is present.");
46 ec=4;
47 break;
48 case CDS_DRIVE_NOT_READY:
49 printf("Drive is not ready.");
50 ec=5;
51 break;
52 case CDS_DISC_OK:
53 printf("A disc is in the drive.");
54 ec=0;
55 break;
56 default:
57 printf("Um, we shouldn't be here!");
58 ec=1;
60 printf("\n");
62 return ec;
65 /* end of C code */