예제 #1
0
int getLocalIPaddresses(struct turn_info *turnInfo, int type, char *iface)
{

    if (!getLocalInterFaceAddrs( (struct sockaddr *)&turnInfo->localIp4, iface, AF_INET, IPv6_ADDR_NONE, false)){
        //fprintf(stderr,"Unable to find local IPv4 interface addresses\n");
    }else{
        turnInfo->turnAlloc_44.sockfd = createLocalUDPSocket(AF_INET,
                                                             (struct sockaddr *)&turnInfo->localIp4,
                                                             (struct sockaddr *)&turnInfo->turnAlloc_44.hostAddr,
                                                             0);
        if(type == SOCK_STREAM){

            turnInfo->turnAlloc_44.sockfd = createLocalTCPSocket(AF_INET,
                                                                 turnInfo,
                                                                 3478);

        }

        turnInfo->turnAlloc_46.sockfd = createLocalUDPSocket(AF_INET,
                                                             (struct sockaddr *)&turnInfo->localIp4,
                                                             (struct sockaddr *)&turnInfo->turnAlloc_46.hostAddr,
                                                             0);
        
    }

    if (!getLocalInterFaceAddrs((struct sockaddr *)&turnInfo->localIp6_ula, iface, AF_INET6, IPv6_ADDR_ULA, true) &&
        !getLocalInterFaceAddrs((struct sockaddr *)&turnInfo->localIp6_ula, iface, AF_INET6, IPv6_ADDR_ULA, false) ){
        fprintf(stderr,"Unable to find local IPv6 Privacy interface addresses\n");
    }else{
        //TODO: Revrite... sockets overwite each other...
        turnInfo->turnAlloc_64.sockfd = createLocalUDPSocket(AF_INET6,
                                                             (struct sockaddr *)&turnInfo->localIp6_ula,
                                                             (struct sockaddr *)&turnInfo->turnAlloc_64.hostAddr,
                                                             0);
        turnInfo->turnAlloc_66.sockfd = createLocalUDPSocket(AF_INET6,
                                                             (struct sockaddr *)&turnInfo->localIp6_ula,
                                                             (struct sockaddr *)&turnInfo->turnAlloc_66.hostAddr,
                                                             0);
    }

    if (!getLocalInterFaceAddrs((struct sockaddr *)&turnInfo->localIp6, iface, AF_INET6, IPv6_ADDR_NORMAL, true) &&
        !getLocalInterFaceAddrs((struct sockaddr *)&turnInfo->localIp6, iface, AF_INET6, IPv6_ADDR_NORMAL, false) ){
        //fprintf(stderr,"Unable to find local IPv6 interface addresses\n");
    }else{
        //TODO: Revrite... sockets overwite each other...
        turnInfo->turnAlloc_64.sockfd = createLocalUDPSocket(AF_INET6,
                                                             (struct sockaddr *)&turnInfo->localIp6,
                                                             (struct sockaddr *)&turnInfo->turnAlloc_64.hostAddr,
                                                             0);
        turnInfo->turnAlloc_66.sockfd = createLocalUDPSocket(AF_INET6,
                                                             (struct sockaddr *)&turnInfo->localIp6,
                                                             (struct sockaddr *)&turnInfo->turnAlloc_66.hostAddr,
                                                             0);
    }
    return 0;
}
예제 #2
0
int
main(int   argc,
     char* argv[])
{
  //struct addrinfo*        servinfo;
  //int                     numbytes;
  //struct sockaddr_storage their_addr;
  //unsigned char           buf[MAXBUFLEN];
  struct sockaddr_storage localAddr;
  char                    interface[10];
  int port;

  //StunMessage            stunRequest;
  //STUN_INCOMING_REQ_DATA pReq;

  pthread_t socketListenThread;

  STUN_CLIENT_DATA*   clientData;
  struct listenConfig listenConfig;

  StunClient_Alloc(&clientData);

  signal(SIGINT, teardown);
  int                 c;
  /* int                 digit_optind = 0; */
  /* set config to default values */
  strncpy(interface, "default", 7);
  port         = 3478;

  static struct option long_options[] = {
    {"interface", 1, 0, 'i'},
    {"port", 1, 0, 'p'},
    {"help", 0, 0, 'h'},
    {"version", 0, 0, 'v'},
    {NULL, 0, NULL, 0}
  };
  if (argc < 1)
  {
    printUsage();
    exit(0);
  }
  int option_index = 0;
  while ( ( c = getopt_long(argc, argv, "hvi:p:j:m:M:w:r:",
                            long_options, &option_index) ) != -1 )
  {
    /* int this_option_optind = optind ? optind : 1; */
    switch (c)
    {
    case 'i':
      strncpy(interface, optarg, max_iface_len);
      break;
    case 'p':
      port = atoi(optarg);
      break;
    case 'h':
      printUsage();
      break;
    case 'v':
      printf("Version %s\n", VERSION_SHORT);
      exit(0);
      break;
    default:
      printf("?? getopt returned character code 0%o ??\n", c);
    }
  }

  if ( !getLocalInterFaceAddrs( (struct sockaddr*)&localAddr,
                                interface,
                                AF_INET,
                                IPv6_ADDR_NORMAL,
                                false ) )
  {
    printf("Error getting IPaddr on %s\n", interface);
    exit(1);
  }

  //sockfd = createSocket(NULL, MYPORT, AI_PASSIVE, servinfo, &p);
  sockfd = createLocalSocket(AF_INET,
                             (struct sockaddr*)&localAddr,
                             SOCK_DGRAM,
                             port);

  listenConfig.tInst  = clientData;
  listenConfig.socketConfig[0].sockfd = sockfd;
  listenConfig.socketConfig[0].user   = NULL;
  listenConfig.socketConfig[0].pass   = PASSWORD;
  listenConfig.stun_handler           = stunHandler;
  listenConfig.numSockets             = 1;



  pthread_create(&socketListenThread,
                 NULL,
                 socketListenDemux,
                 (void*)&listenConfig);

  while (1)
  {
    printf("stunserver: waiting to recvfrom...\n");

    sleep(1000);
  }
}
예제 #3
0
int
main(int   argc,
     char* argv[])
{
  struct sockaddr_storage localAddr;
  char                    interface[10];
  int                     port;

  transIDSinUse = 0;

  pthread_t socketListenThread;
  pthread_t cleanupThread;

  STUN_CLIENT_DATA*   clientData;
  struct listenConfig listenConfig;

  StunClient_Alloc(&clientData);
  /* StunClient_RegisterLogger(clientData, */
  /*                          stundbg, */
  /*                          NULL); */

  signal(SIGINT, teardown);
  int c;
  /* int                 digit_optind = 0; */
  /* set config to default values */
  strncpy(interface, "default", 7);
  port          = 3478;
  upstream_loss = 0;

  static struct option long_options[] = {
    {"interface", 1, 0, 'i'},
    {"port", 1, 0, 'p'},
    {"upstream", 1, 0, 'u'},
    {"csv", 0, 0, '2'},
    {"help", 0, 0, 'h'},
    {"version", 0, 0, 'v'},
    {NULL, 0, NULL, 0}
  };
  if (argc < 1)
  {
    printUsage();
    exit(0);
  }
  int option_index = 0;
  while ( ( c = getopt_long(argc, argv, "h2vi:p:m:u:",
                            long_options, &option_index) ) != -1 )
  {
    /* int this_option_optind = optind ? optind : 1; */
    switch (c)
    {
    case 'i':
      strncpy(interface, optarg, max_iface_len);
      break;
    case 'p':
      port = atoi(optarg);
      break;
    case 'u':
      upstream_loss = atoi(optarg);
      break;
    case '2':
      csv_output = true;
      break;
    case 'h':
      printUsage();
      break;
    case 'v':
      printf("Version %s\n", VERSION_SHORT);
      exit(0);
      break;
    default:
      printf("?? getopt returned character code 0%o ??\n", c);
    }
  }

  if ( !getLocalInterFaceAddrs( (struct sockaddr*)&localAddr,
                                interface,
                                AF_INET,
                                IPv6_ADDR_NORMAL,
                                false ) )
  {
    printf("Error getting IPaddr on %s\n", interface);
    exit(1);
  }

  /* sockfd = createSocket(NULL, MYPORT, AI_PASSIVE, servinfo, &p); */
  sockfd = createLocalSocket(AF_INET,
                             (struct sockaddr*)&localAddr,
                             SOCK_DGRAM,
                             port);
  pthread_mutex_init(&mutexTransId, NULL);
  pthread_create(&cleanupThread, NULL, transIDCleanup, (void*)transIDs);

  listenConfig.tInst                  = clientData;
  listenConfig.socketConfig[0].sockfd = sockfd;
  listenConfig.socketConfig[0].user   = NULL;
  listenConfig.socketConfig[0].pass   = PASSWORD;
  listenConfig.stun_handler           = stunHandler;
  listenConfig.numSockets             = 1;

  pthread_create(&socketListenThread,
                 NULL,
                 socketListenDemux,
                 (void*)&listenConfig);
  pause();

}