added ignore file
[my-code/dmsd.git] / dmsd.c
1 /*
2  * dmsd - digital media soft decrypt
3  * 
4  * author: hackbard@hackdaworld.dyndns.org
5  *
6  */
7
8 #define _GNU_SOURCE
9 #include <stdio.h>
10 #include <string.h>
11 #include <stdlib.h>
12 #include <unistd.h>
13 #include <sys/types.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16 #include <arpa/inet.h>
17
18 #include "dmsd.h"
19
20 int main(int argc,char *argv[]) {
21
22   /* file descriptors */
23   int v_fd,a_fd;
24   /* pid's */
25   int vpid,apid;
26   /* ip */
27   struct sockaddr_in dbox_addr;
28   /* some ints */
29   int status,recvd_bytes;
30
31   if(argc!=4) {
32     printf("usage: %s <video pid> <audio pid> <dbox ip address>\n",argv[0]);
33     return -1;
34   }
35
36   //sscanf(argv[1],"%x",vpid);
37   vpid=atoi(argv[1]);
38   //sscanf(argv[2],"%x",apid);
39   apid=atoi(argv[2]);
40
41   printf("using video pid %x & audio pid %x ...\n",vpid,apid);
42
43   if((v_fd=socket(AF_INET,SOCK_STREAM,0)) == -1) {
44     printf("can't open socket for video.\n");
45     return -1;
46   }
47   if((a_fd=socket(AF_INET,SOCK_STREAM,0)) == -1) {
48     printf("can't open socket for audio.\n");
49     return -1;
50   }
51
52   memset(&dbox_addr,0,sizeof(dbox_addr));
53   dbox_addr.sin_family=AF_INET;
54   dbox_addr.sin_port=htons(DBOX2_TS_PORT);
55   dbox_addr.sin_addr.s_addr=inet_addr(argv[3]);
56
57   if(connect(v_fd,(struct sockaddr *)&dbox_addr,sizeof(dbox_addr))==-1) {
58     printf("unable to connect. (video pid)\n");
59     perror("connect");
60     exit(1);
61   }
62
63   dprintf(v_fd,"GET /%x HTTP/1.0\r\n\r\n",vpid);
64   printf("debug: GET /%x HTTP/1.0\r\n\r\nwritten to video fd\n",vpid);
65   //dprintf(v_fd,"GET /%x",vpid);
66   //printf("debug: GET /%x\nwritten to video fd\n",vpid);
67
68   status=1; 
69   while(status) {
70     unsigned char buf[BUFFER_LENGTH];
71
72     status=recv(v_fd,buf,sizeof(buf),0);
73     write(1,buf,status);
74   }
75   
76   return 0;
77 }
78