| 
 | ||||||
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
int
make_socket (uint16_t port)
{
  int sock;
  struct sockaddr_in name;
  /* Soketi oluşturalım. */
  sock = socket (PF_INET, SOCK_STREAM, 0);
  if (sock < 0)
    {
      perror ("socket");
      exit (EXIT_FAILURE);
    }
  /* Sokete bir isim verelim. */
  name.sin_family = AF_INET;
  name.sin_port = htons (port);
  name.sin_addr.s_addr = htonl (INADDR_ANY);
  if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0)
    {
      perror ("bind");
      exit (EXIT_FAILURE);
    }
  return sock;
}
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
void
init_sockaddr (struct sockaddr_in *isim,
                const char *konakismi,
                uint16_t port)
{
  struct hostent *konakbilgisi;
  isim->sin_family = AF_INET;
  isim->sin_port = htons (port);
  konakbilgisi = gethostbyname (konakismi);
  if (konakbilgisi == NULL)
    {
      fprintf (stderr, "%s diye bir konak yok.\n", konakismi);
      exit (EXIT_FAILURE);
    }
  isim->sin_addr = *(struct in_addr *) konakbilgisi->h_addr;
}
| 
 | |||||||||