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.
23 * A utility for reading from a stream
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>
40 int main(int argc, char *argv[])
42 struct sockaddr_in sin;
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");
58 hp = gethostbyname(argv[1]);
60 fprintf(stderr, "Unable to lookup IP for host '%s'\n", argv[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);
73 fprintf(stderr, "Unable to allocate socket!\n");
77 res = connect(s, (struct sockaddr *)&sin, sizeof(sin));
80 fprintf(stderr, "Unable to connect to host!\n");
86 res = read(s, buf, sizeof(buf));
91 memset(&tv, 0, sizeof(tv));
95 select(2, NULL, &wfds, NULL, &tv);
97 if (FD_ISSET(1, &wfds))