1 /* receive.c - receive from streaming server
13 /* socket and bind stuff */
14 #include <sys/types.h>
15 #include <sys/socket.h>
18 #include <netinet/in.h>
21 #include <arpa/inet.h>
29 int main(int argc, char *argv[]) {
31 struct sockaddr_in target_addr;
32 socklen_t target_addr_len;
33 int receive_bytes, write_bytes;
36 printf("usage: %s <port>\n",argv[0]);
40 if((receive_fd=socket(AF_INET,SOCK_STREAM,0)) == -1) {
41 printf("can't open socket.\n");
45 memset(&target_addr,0,sizeof(target_addr));
46 target_addr.sin_family=AF_INET;
47 target_addr.sin_port=htons(atoi(argv[2]));
48 target_addr.sin_addr.s_addr=inet_addr(argv[1]);
50 if(connect(receive_fd,(struct sockaddr *)&target_addr,sizeof(target_addr))==-1) {
51 printf("unable to connect.\n");
56 printf("connected.\n");
59 while(receive_bytes>0) {
60 unsigned char buf[1000];
61 receive_bytes=recv(receive_fd,buf,sizeof(buf),0);
62 write_bytes=write(1,buf,sizeof(buf));
66 printf("connection closed ...\n");
67 printf("%d from %d total bytes written.\n",write_bytes,receive_bytes);