fix syntax help
[record-dvb] / dump-stream.c
CommitLineData
cc319f8b 1#include <features.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <sys/time.h>
5#include <time.h>
6#include <sys/socket.h>
7#include <sys/types.h>
8#include <sys/stat.h>
9#include <fcntl.h>
10#include <unistd.h>
11#include <strings.h>
c0833e33 12#include <netdb.h>
cc319f8b 13
14#include "mcast.h"
c0833e33 15#include "http.h"
16#include "sap.h"
17#include "common.h"
cc319f8b 18
19#define CHUNKSIZE 1500
20
21int main(int argc, char **argv)
22{
23 char *url;
24 int bytes, written, i;
25 int in;
26 char buffer[CHUNKSIZE];
27
28 if (argc == 2) {
29 url = argv[1];
30 } else {
c97cc707 31 fprintf(stderr,"Syntax: %s URL|SAPServiceName\n", argv[0]);
cc319f8b 32 exit(EXIT_FAILURE);
33 }
34
c0833e33 35 if (!is_url(url)) {
36 char *service_url;
37 if ((service_url = get_url_from_sap(url))) {
38 printf("SAP says: '%s' -> %s\n", url, service_url);
39 url = service_url;
40 }
41 }
42
43 if (is_http(url)) {
44 if ((in = open_http(url)) < 0) {
45 fprintf(stderr,"Can't open url %s!\n",url);
46 exit(EXIT_FAILURE);
47 }
48 } else if (is_mcast(url)) {
49 if ((in = open_mcast(url)) < 0) {
50 fprintf(stderr,"Can't open url %s!\n",url);
51 exit(EXIT_FAILURE);
52 }
53 } else {
54 printf("URL '%s' not supported!\n", url);
cc319f8b 55 exit(EXIT_FAILURE);
56 }
57
58 while(1) {
59 if ((bytes = recv(in, buffer, CHUNKSIZE, 0)) < 1) {
60 perror("recv");
61 exit(EXIT_FAILURE);
62 }
63
64 written = 0;
65 do {
66 if ((i = write(STDOUT_FILENO, buffer, bytes-written)) < 0) {
67 perror("write");
68 exit(EXIT_FAILURE);
69 }
70 written += i;
71 } while(written < bytes);
72 }
73
74 close(in);
75
76 return EXIT_SUCCESS;
77}
Impressum, Datenschutz