Esempio n. 1
0
int main(int argc, char *argv[]) {
  char buf[80];
  pthread_attr_t attr;
  char *in_dev, *out_dev;
  int status;

  if (argc != 3) {
    fprintf(stderr, "usage: vrouter <in_dev> <out_dev>\n");
    return 1;
  }
  in_dev = argv[1];
  out_dev = argv[2];
  inet_aton(next_router_s, &next_router);
  debug_printf("NextRouter=%s\n", _inet_ntoa_r(&next_router, buf, sizeof(buf)));

  if (get_device_info(in_dev, device[0].hwaddr, &device[0].addr,
                      &device[0].subnet, &device[0].netmask) == -1) {
    debug_printf("GetDeviceInfo:error:%s\n", in_dev);
    return -1;
  }

  if ((device[0].soc = init_raw_socket(in_dev, 1, 0)) == -1) {
    debug_printf("InitRawSocket:error:%s\n",in_dev);
    return -1;
  }
  if (get_device_info(out_dev, device[1].hwaddr, &device[1].addr,
                      &device[1].subnet, &device[1].netmask) == -1) {
    debug_printf("GetDeviceInfo:error:%s\n", out_dev);
    return -1;
  }
  if ((device[1].soc = init_raw_socket(out_dev, 1, 0)) == -1) {
    debug_printf("InitRawSocket:error:%s\n",out_dev);
    return -1;
  }

  disable_ip_forward();

  pthread_attr_init(&attr);
  if ((status = pthread_create(&buf_tid, &attr, buffer_thread, NULL)) != 0) {
    debug_printf("pthread_create:%s\n", strerror(status));
  }

  signal(SIGPIPE, SIG_IGN);
  signal(SIGTTIN, SIG_IGN);
  signal(SIGTTOU, SIG_IGN);

  IP2MAC *ip2mac = ip_2_mac(get_opposite_dev(0), next_router.s_addr, NULL);
  debug_printf("router start\n");
  router();
  debug_printf("router end\n");

  close(device[0].soc);
  close(device[1].soc);

  return 0;
}
Esempio n. 2
0
GYINT32 GYNetAddress::GetAddressString(char* address, GYINT32 len)
{
    GYINT32 result = INVALID_VALUE;
    do
    {
        if (0 != _inet_ntoa_r(m_sockAddr.sin_addr, address, len))
        {
            break;
        }
        result = 0;
    }
    while (GYFALSE);
    return result;
}