]> hackdaworld.org Git - my-code/ivac.git/commitdiff
added hcat.c as a tutorial for internet communication using sockets
authorhackbard <hackbard>
Fri, 4 Oct 2002 01:08:17 +0000 (01:08 +0000)
committerhackbard <hackbard>
Fri, 4 Oct 2002 01:08:17 +0000 (01:08 +0000)
tutorials/hcat.c [new file with mode: 0644]

diff --git a/tutorials/hcat.c b/tutorials/hcat.c
new file mode 100644 (file)
index 0000000..da8c006
--- /dev/null
@@ -0,0 +1,42 @@
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <signal.h>
+#include <stdio.h>
+
+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;
+}