示例#1
0
文件: interposer.c 项目: dozylynx/v4v
INTERPOSE (connect, int, int sockfd, const struct sockaddr * addr,
           socklen_t addrlen)
{
  v4v_addr_t peer, me;
  char *val, *end;
  int addend, ret;

  CHECK_INTERPOSE (connect);

  if (!is_our_fd (sockfd))
    return orig_connect (sockfd, addr, addrlen);

  if (v4v_map_sa_to_v4va (&peer, addr, addrlen))
    return -EINVAL;

  /* Bind the socket to a specific port if requested */
  val = getenv ("V4V_CLIENT_PORT_ADDEND");
  if (val != NULL) {
    addend = strtol(val, &end, 10);
    /* Sanitize the addend */
    if (end == NULL || *end != '\0' || addend < 0)
      return -EINVAL;
    me.domain = V4V_DOMID_ANY;
    me.port = peer.port + addend;
    DEBUG_PRINTF ("BINDING CLIENT TO port %d\n", (int) me.port);
    DEBUG_PRINTF ("  AND SET %d AS THE PARTNER\n", (int) peer.domain);
    ret = v4v_bind(sockfd, &me, peer.domain);
    if (ret)
      return ret;
  }

  DEBUG_PRINTF ("CONNECTING TO %d:%d\n", (int) peer.domain, (int) peer.port);

  return v4v_connect (sockfd, &peer);
}
示例#2
0
INTERPOSE (connect, int, int sockfd, const struct sockaddr * addr,
           socklen_t addrlen)
{
  v4v_addr_t peer;

  CHECK_INTERPOSE (connect);

  if (!is_our_fd (sockfd))
    return orig_connect (sockfd, addr, addrlen);

  if (v4v_map_sa_to_v4va (&peer, addr, addrlen))
    return -EINVAL;

  DEBUG_PRINTF ("CONNECTING TO %d:%d\n", (int) peer.domain, (int) peer.port);

  return v4v_connect (sockfd, &peer);
}