daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Feb 16th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int Making_Socket( int * list_sd, struct hosten ** server, struct sockaddr_in * addr, char * adres, int on, long port)
  2. {
  3.    int rc=0;
  4.    *list_sd = socket(AF_INET, SOCK_STREAM, 0);
  5.    if (*list_sd < 0)
  6.    {
  7.      fprintf(stderr, "Error in function socket()\n");
  8.      exit(-1);
  9.    }
  10.  
  11.    *server = gethostbyname(adres);
  12.    if(*server == NULL)
  13.    {
  14.       fprintf(stderr, "Wrong adress \n");
  15.       exit(-1);
  16.    }
  17.  
  18.   rc = setsockopt(*list_sd, SOL_SOCKET,  SO_REUSEADDR, (char *)&on, sizeof(on));
  19.   if (rc < 0)
  20.      error("setsockopt()", *list_sd);
  21.  
  22.   rc = ioctl(*list_sd, FIONBIO, (char *)&on);
  23.   if (rc < 0)
  24.      error("ioctl()", *list_sd);
  25.  
  26.  //**************************                        
  27.  
  28.   memset(&addr, 0, sizeof(*addr));
  29.   addr.sin_addr.s_addr = inet_addr(adres);
  30.   addr.sin_family = AF_INET;
  31.   bcopy((char*)(*server)->h_addr, (char*)addr.sin_addr.s_addr, (*server)->h_length);
  32.   addr.sin_port = htons(port);
  33.  
  34.   rc = bind(*list_sd, (struct sockaddr *)addr, sizeof(*addr));
  35.   if (rc < 0)
  36.      error("bind()", *list_sd);
  37.  
  38.   rc = listen(*list_sd, 128);
  39.   if (rc < 0)
  40.      error("listen()", *list_sd);        
  41. }
  42.  
  43. Making_Socket(&list_sd, &server, &addr, adres, on, port);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top