54 #include <sys/types.h> 55 #include <sys/socket.h> 56 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__Darwin__) || defined(__CYGWIN__) || defined(__DragonFly__) 57 #include <netinet/in.h> 62 int main(
int argc,
char *argv[])
64 struct sockaddr_in sin;
73 fprintf(stderr,
"streamplayer -- A utility for reading from a raw TCP stream.\n");
74 fprintf(stderr,
"Written for use with Asterisk (http://www.asterisk.org)\n");
75 fprintf(stderr,
"Copyright (C) 2005 -- Russell Bryant -- Digium, Inc.\n\n");
76 fprintf(stderr,
"Usage: ./streamplayer <ip> <port>\n");
82 fprintf(stderr,
"Unable to lookup IP for host '%s'\n", argv[1]);
86 memset(&sin, 0,
sizeof(sin));
88 sin.sin_family = AF_INET;
89 sin.sin_port = htons(atoi(argv[2]));
90 memcpy(&sin.sin_addr, hp->h_addr,
sizeof(sin.sin_addr));
92 s = socket(AF_INET, SOCK_STREAM, 0);
95 fprintf(stderr,
"Unable to allocate socket!\n");
99 res = connect(s, (
struct sockaddr *)&sin,
sizeof(sin));
102 fprintf(stderr,
"Unable to connect to host!\n");
108 res = read(s, buf,
sizeof(buf));
113 memset(&tv, 0,
sizeof(tv));
119 if (FD_ISSET(1, &wfds)) {
120 if (write(1, buf, res) < 1) {
int main(int argc, char *argv[])
static struct hostent * hp