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