4 * A utility for reading from a stream
6 * Copyright (C) 2005, Digium, Inc.
8 * Russell Bryant <russell@digium.com>
10 * This program is free software, distributed under the terms of
11 * the GNU General Public License
21 #include <sys/types.h>
22 #include <sys/socket.h>
23 #if defined(__FreeBSD__)
24 #include <netinet/in.h>
29 int main(int argc, char *argv[])
31 struct sockaddr_in sin;
40 fprintf(stderr, "Usage: ./streamplayer <ip> <port>\n");
44 hp = gethostbyname(argv[1]);
46 fprintf(stderr, "Unable to lookup IP for host '%s'\n", argv[1]);
50 memset(&sin, 0, sizeof(sin));
52 sin.sin_family = AF_INET;
53 sin.sin_port = htons(atoi(argv[2]));
54 memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
56 s = socket(AF_INET, SOCK_STREAM, 0);
59 fprintf(stderr, "Unable to allocate socket!\n");
63 res = connect(s, (struct sockaddr *)&sin, sizeof(sin));
66 fprintf(stderr, "Unable to connect to host!\n");
72 res = read(s, buf, sizeof(buf));
77 memset(&tv, 0, sizeof(tv));
81 select(2, NULL, &wfds, NULL, &tv);
83 if (FD_ISSET(1, &wfds))