Guest User

Untitled

a guest
Dec 11th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <sys/socket.h>
  2. #include <netinet/in.h>
  3. #include <stdio.h>
  4. #include <strings.h>
  5.  
  6. int main(int argc, char** argv) {
  7. struct sockaddr_in6 server;
  8. char buf[20];
  9. int no, asd, sd = socket(AF_INET6, SOCK_STREAM, 0);
  10.  
  11. bzero(&server, sizeof(server));
  12. server.sin6_family = AF_INET6;
  13. server.sin6_addr = in6addr_any;
  14. server.sin6_port = 4242;
  15. bind(sd, (struct sockaddr*) &server, sizeof(server));
  16. listen(sd, 5);
  17. while (1) {
  18. printf("Waiting for connection....\n");
  19. asd = accept(sd, 0, 0);/* Block until complete connect */
  20. if ((no = read(asd, buf, sizeof(buf))) != -1)
  21. printf("Recieved %d bytes: %s\n", no, buf);
  22. close(asd);
  23. }
  24. close(sd);
  25.  
  26. }
Add Comment
Please, Sign In to add comment