--- /dev/null
+/* receive.c - receive from streaming server
+ *
+ * author: hackbard
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/* memset */
+#include <string.h>
+
+/* socket and bind stuff */
+#include <sys/types.h>
+#include <sys/socket.h>
+
+/* sockkaddr_in */
+#include <netinet/in.h>
+
+/* inet_ntoa ... */
+#include <arpa/inet.h>
+
+/* errno stuff ... */
+#include <errno.h>
+
+/* read, close */
+#include <unistd.h>
+
+int main(int argc, char *argv[]) {
+ int receive_fd;
+ struct sockaddr_in target_addr;
+ socklen_t target_addr_len;
+ int receive_bytes, write_bytes;
+
+ if(argc!=3) {
+ printf("usage: %s <port>\n",argv[0]);
+ exit(1);
+ }
+
+ if((receive_fd=socket(AF_INET,SOCK_STREAM,0)) == -1) {
+ printf("can't open socket.\n");
+ exit(1);
+ }
+
+ memset(&target_addr,0,sizeof(target_addr));
+ target_addr.sin_family=AF_INET;
+ target_addr.sin_port=htons(atoi(argv[2]));
+ target_addr.sin_addr.s_addr=inet_addr(argv[1]);
+
+ if(connect(receive_fd,(struct sockaddr *)&target_addr,sizeof(target_addr))==-1) {
+ printf("unable to connect.\n");
+ perror("connect");
+ exit(1);
+ }
+
+ printf("connected.\n");
+
+ receive_bytes=1;
+ while(receive_bytes>0) {
+ unsigned char buf[1000];
+ receive_bytes=recv(receive_fd,buf,sizeof(buf),0);
+ write_bytes=write(1,buf,sizeof(buf));
+ }
+
+ close(receive_fd);
+ printf("connection closed ...\n");
+ printf("%d from %d total bytes written.\n",write_bytes,receive_bytes);
+
+ return 0;
+}