Exemplo n.º 1
0
int open_sf_source(const char *host, int port)
/* Returns: file descriptor for serial forwarder at host:port
 */
{
  int fd = socket(AF_INET, SOCK_STREAM, 0);
  struct hostent *entry;
  struct sockaddr_in addr;

  if (fd < 0)
    return fd;

  entry = gethostbyname(host);
  if (!entry)
    {
      close(fd);
      return -1;
    }      

  addr.sin_family = entry->h_addrtype;
  memcpy(&addr.sin_addr, entry->h_addr, entry->h_length);
  addr.sin_port = htons(port);
  if (connect(fd, (struct sockaddr *)&addr, sizeof addr) < 0)
    {
      close(fd);
      return -1;
    }

  if (init_sf_source(fd) < 0)
    {
      close(fd);
      return -1;
    }

  return fd;
}
Exemplo n.º 2
0
void new_client(int fd)
{
  fcntl(fd, F_SETFL, 0);
  if (init_sf_source(fd) < 0)
    close(fd);
  else
    add_client(fd);
}
Exemplo n.º 3
0
int init_telos_source(int fd)

{
  int result;
  pthread_mutex_lock(&sfwritemutex);
  //add any telos specific code here
  result = init_sf_source(fd);
  pthread_mutex_unlock(&sfwritemutex);
  return result;
}