From f132c66f296623bbb2504a762514629f8508a729 Mon Sep 17 00:00:00 2001 From: hackbard Date: Wed, 16 Oct 2002 03:15:43 +0000 Subject: [PATCH] added streaming support --- ivac.c | 2 ++ stream.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 stream.c diff --git a/ivac.c b/ivac.c index 6d8e357..25822a8 100644 --- a/ivac.c +++ b/ivac.c @@ -6,3 +6,5 @@ #include + +// in development diff --git a/stream.c b/stream.c new file mode 100644 index 0000000..b62f571 --- /dev/null +++ b/stream.c @@ -0,0 +1,72 @@ +/* stream.c - streaming server + * + * author: hackbard + * + */ + +#include +#include + +/* memset */ +#include + +/* socket and bind stuff */ +#include +#include + +/* sockkaddr_in */ +#include + +/* inet_ntoa ... */ +#include + + +int main(int argc, char *argv[]) { + int listen_fd, send_fd; + struct sockaddr_in local_addr, *remote_addr; + int send_bytes, read_bytes; + + if(argc!=2) { + printf("usage: %s \n",argv[0]); + exit(1); + } + + if(listen_fd=socket(AF_INET,SOCK_STREAM,0) == -1) { + printf("can't open socket.\n"); + exit(1); + } + + local_addr.sin_family=AF_INET; + local_addr.sin_port=htons(atoi(argv[1])); + local_addr.sin_addr.s_addr=htonl(INADDR_ANY); + memset(&(local_addr.sin_zero),'\0',8); + + if(bind(listen_fd,(struct sockaddr)&local_addr,sizeof(struct sockaddr))==-1) { + printf("unable to bind on port %d.\n",atoi(argv[1]); + exit(1); + } + + if(listen(listen_fd,1)==-1) { + printf("error listening on port %d.\n",atoi(argv[1])); + exit(1); + } + + if(send_fd=accept(listen_fd,(struct sockaddr *)remote_addr, + sizeof(struct sockaddr_in)) { + printf("accepting connection from %s port %d.\n", + inet_ntoa(remote_addr->sin_addr.s_addr), + ntohs(remote_addr->sin_port)); + + /* send stuff .... */ + read_bytes=1; + while(read_bytes>0) { + char buf[1000]; + read_bytes=read(stdin,(void *)buf,sizeof(buf)); + send_bytes=send(send_fd,buf,sizeof(buf),0); + } + + close(send_fd); + printf("connection closed ...\n"); + prinrf("%d from %d total bytes sent.\n",send_bytes,read_bytes); + return 0; +} -- 2.39.2