don't re-do setup operations for translators that can dynamically register themselves
[asterisk-bristuff.git] / utils / streamplayer.c
blob24f3142b8a11d941e566a3804ff104452a2d2a87
1 /*
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 * streamplayer.c
23 * A utility for reading from a stream
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <netdb.h>
31 #include <unistd.h>
32 #include <sys/types.h>
33 #include <sys/socket.h>
34 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__Darwin__) || defined(__CYGWIN__)
35 #include <netinet/in.h>
36 #endif
37 #include <sys/time.h>
40 int main(int argc, char *argv[])
42 struct sockaddr_in sin;
43 struct hostent *hp;
44 int s;
45 int res;
46 char buf[2048];
47 fd_set wfds;
48 struct timeval tv;
50 if (argc != 3) {
51 fprintf(stderr, "streamplayer -- A utility for reading from a stream.\n");
52 fprintf(stderr, "Written for use with Asterisk (http://www.asterisk.org)\n");
53 fprintf(stderr, "Copyright (C) 2005 -- Russell Bryant -- Digium, Inc.\n\n");
54 fprintf(stderr, "Usage: ./streamplayer <ip> <port>\n");
55 exit(1);
58 hp = gethostbyname(argv[1]);
59 if (!hp) {
60 fprintf(stderr, "Unable to lookup IP for host '%s'\n", argv[1]);
61 exit(1);
64 memset(&sin, 0, sizeof(sin));
66 sin.sin_family = AF_INET;
67 sin.sin_port = htons(atoi(argv[2]));
68 memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
70 s = socket(AF_INET, SOCK_STREAM, 0);
72 if (s < 0) {
73 fprintf(stderr, "Unable to allocate socket!\n");
74 exit(1);
77 res = connect(s, (struct sockaddr *)&sin, sizeof(sin));
79 if (res) {
80 fprintf(stderr, "Unable to connect to host!\n");
81 close(s);
82 exit(1);
85 while (1) {
86 res = read(s, buf, sizeof(buf));
88 if (res < 1)
89 break;
91 memset(&tv, 0, sizeof(tv));
92 FD_ZERO(&wfds);
93 FD_SET(1, &wfds);
95 select(2, NULL, &wfds, NULL, &tv);
97 if (FD_ISSET(1, &wfds))
98 write(1, buf, res);
101 close(s);
102 exit(res);