From: hackbard Date: Fri, 4 Oct 2002 01:08:17 +0000 (+0000) Subject: added hcat.c as a tutorial for internet communication using sockets X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=ab670fd034b5765c443858826a0d2cb3363a1506;p=my-code%2Fivac.git added hcat.c as a tutorial for internet communication using sockets --- diff --git a/tutorials/hcat.c b/tutorials/hcat.c new file mode 100644 index 0000000..da8c006 --- /dev/null +++ b/tutorials/hcat.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) { + int listenfd, connfd,rres; + socklen_t clilen; + struct sockaddr_in cliaddr, servaddr; + unsigned char foo[1500-12-12]; + + listenfd = socket(AF_INET, SOCK_STREAM, 0); + + memset(&servaddr, 0, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + servaddr.sin_port = htons(2350); + + bind(listenfd, &servaddr, sizeof(servaddr)); + + listen(listenfd, 1); + + clilen = sizeof(cliaddr); + connfd = accept(listenfd, &cliaddr, &clilen); + fprintf(stderr,"connected\n"); + + + rres=1; + while(rres>0) { + rres=read(connfd,foo,sizeof(foo)); + fprintf(stderr,"%d bytes read\n",rres); + write(1,foo,rres); + } + + return 0; +}