Advertisement
ringneckparrot

listen

Apr 9th, 2012
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. /****************************************************************************
  2.     ringneckparrot (c)
  3.     License: http://creativecommons.org/licenses/by-nc-sa/3.0/
  4.    
  5.     Contact Me:
  6.     Email: ringneckparrot@hotmail.com
  7.     Facebook: http://www.facebook.com/ringneckparrot
  8.     Twitter ID: pp4rr0t
  9.     SecurityTube: http://www.securitytube.net/user/ringneckparrot
  10.  
  11. ****************************************************************************/
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <sys/types.h>
  16. #include <sys/socket.h>
  17. #include <strings.h>
  18. #include <errno.h>
  19. #include <netinet/in.h>
  20. #define ErrorValue -1
  21.  
  22. main()
  23. {
  24.     int sock;
  25.     int bindsock;
  26.     int listensock;
  27.     struct sockaddr_in info;
  28.  
  29.     sock = socket(AF_INET, SOCK_STREAM, 0);
  30.     if ( sock == ErrorValue )
  31.     {
  32.         perror("Socket Error: ");
  33.         exit(-1);
  34.     }
  35.  
  36.     bzero(&info, sizeof(info));
  37.     info.sin_family = AF_INET;
  38.     info.sin_port = htons(1234);
  39.     info.sin_addr.s_addr = INADDR_ANY;
  40.    
  41.     bindsock = bind(sock, (struct sockaddr *)&info, sizeof(info));
  42.     if ( bindsock == ErrorValue )
  43.     {
  44.         perror("Bind Error: ");
  45.         exit(-1);
  46.     }
  47.    
  48.     listensock = listen(sock, 10);
  49.     if ( listensock == ErrorValue )
  50.     {
  51.         perror("Listen Error: ");
  52.         exit(-1);
  53.     }
  54.    
  55.    
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement