2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Russell Bryant <russell@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \author Russell Bryant <russell@digium.com>
23 * \brief A utility for reading from a raw TCP stream
25 * This application is intended for use when a raw TCP stream is desired to be
26 * used as a music on hold source for Asterisk. Some devices are capable of
27 * taking some kind of audio input and provide it as a raw TCP stream over the
28 * network, which is what inspired someone to fund this to be written.
29 * However, it would certainly be possible to write your own server application
30 * to provide music over a TCP stream from a centralized location.
32 * This application is quite simple. It just reads the data from the TCP
33 * stream and dumps it straight to stdout. Due to the way Asterisk handles
34 * music on hold sources, this application checks to make sure writing
35 * to stdout will not be a blocking operation before doing so. If so, the data
36 * is just thrown away. This ensures that the stream will continue to be
37 * serviced, even if Asterisk is not currently using the source.
39 * \todo Update this application to be able to connect to a stream via HTTP,
40 * since that is the #1 most requested feature, and it would be quite useful.
41 * A lot of people think that is what this is for and email me when it does
50 #include <sys/types.h>
51 #include <sys/socket.h>
52 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__Darwin__) || defined(__CYGWIN__)
53 #include <netinet/in.h>
58 int main(int argc
, char *argv
[])
60 struct sockaddr_in sin
;
69 fprintf(stderr
, "streamplayer -- A utility for reading from a raw TCP stream.\n");
70 fprintf(stderr
, "Written for use with Asterisk (http://www.asterisk.org)\n");
71 fprintf(stderr
, "Copyright (C) 2005 -- Russell Bryant -- Digium, Inc.\n\n");
72 fprintf(stderr
, "Usage: ./streamplayer <ip> <port>\n");
76 hp
= gethostbyname(argv
[1]);
78 fprintf(stderr
, "Unable to lookup IP for host '%s'\n", argv
[1]);
82 memset(&sin
, 0, sizeof(sin
));
84 sin
.sin_family
= AF_INET
;
85 sin
.sin_port
= htons(atoi(argv
[2]));
86 memcpy(&sin
.sin_addr
, hp
->h_addr
, sizeof(sin
.sin_addr
));
88 s
= socket(AF_INET
, SOCK_STREAM
, 0);
91 fprintf(stderr
, "Unable to allocate socket!\n");
95 res
= connect(s
, (struct sockaddr
*)&sin
, sizeof(sin
));
98 fprintf(stderr
, "Unable to connect to host!\n");
104 res
= read(s
, buf
, sizeof(buf
));
109 memset(&tv
, 0, sizeof(tv
));
113 select(2, NULL
, &wfds
, NULL
, &tv
);
115 if (FD_ISSET(1, &wfds
))