Exemplo n.º 1
0
END_TEST


START_TEST (sockaddr_IPv6_alike)
{
    fail_unless( sockaddr_alike((struct sockaddr *)sockaddr_IPv6_1,
                                (struct sockaddr *)sockaddr_IPv6_1),
                 "alike failed");

    fail_if( sockaddr_alike((struct sockaddr *)sockaddr_IPv6_1,
                            (struct sockaddr *)sockaddr_IPv6_2),
                 "alike failed");

}
Exemplo n.º 2
0
END_TEST

START_TEST (test_sockaddr_int_IPv4_init)
{

    char addr_str[256];
    uint32_t a = 2653302794UL;
    uint16_t port = 4567;
    struct sockaddr_storage a_addr;
    struct sockaddr_storage b_addr;


    sockaddr_initFromIPv4Int((struct sockaddr_in *)&a_addr, htonl(a), htons(port));
    sockaddr_initFromIPv4String((struct sockaddr_in *)&b_addr, "158.38.48.10:4567");

    sockaddr_toString( (struct sockaddr *)&a_addr,
                       addr_str,
                       256,
                       true);

    fail_unless( sockaddr_alike( (struct sockaddr *)&a_addr, (struct sockaddr *)&b_addr) );

    fail_if(sockaddr_initFromIPv4String((struct sockaddr_in *)&b_addr, "158.38.48.10.45"));

    fail_if(sockaddr_initFromIPv4String((struct sockaddr_in *)&b_addr, "158.38.48.10.45.45.67.87:4556"));



}
Exemplo n.º 3
0
END_TEST


START_TEST (test_sockaddr_int_IPv6_init)
{

    char addr_str[256];
    char addr_str_small[4];
    uint8_t a[16] = {0x20, 0x1, 0x4, 0x70, 0xdc, 0x88, 0x0, 0x2, 0x2, 0x26, 0x18, 0xff, 0xfe, 0x92, 0x6d, 0x53};
    uint16_t port = 4567;
    struct sockaddr_storage a_addr;
    struct sockaddr_storage b_addr;

    sockaddr_initFromIPv6Int((struct sockaddr_in6 *)&a_addr, a, htons(port));

    fail_unless(sockaddr_initFromIPv6String((struct sockaddr_in6 *)&b_addr, "[2001:470:dc88:2:226:18ff:fe92:6d53]:4567"));

    sockaddr_toString( (struct sockaddr *)&a_addr,
                       addr_str,
                       256,
                       true);


    fail_unless( sockaddr_alike( (struct sockaddr *)&a_addr, (struct sockaddr *)&b_addr) );


    fail_if( sockaddr_initFromIPv6String((struct sockaddr_in6 *)&b_addr, "[2001:470:dc88:2:226:18ff:fe92:6d53"));

    fail_if( sockaddr_initFromIPv6String((struct sockaddr_in6 *)&b_addr, "[2001:470:dc88:2:226:18ff:fe92:6d53:456]"));


    fail_if( sockaddr_initFromIPv6String((struct sockaddr_in6 *)&b_addr, "2001:470:dc88:2:226:18ff:fe92:6d53:4567]:4567"));

}
Exemplo n.º 4
0
END_TEST

START_TEST (sockaddr_IPv4_copy)
{
    struct sockaddr_storage copy;

    sockaddr_copy((struct sockaddr *)&copy,
                  (const struct sockaddr *)sockaddr_IPv4_1);

    fail_unless( sockaddr_alike((struct sockaddr *)&copy,
                                (struct sockaddr *)sockaddr_IPv4_1),
                 "copy failed");

    fail_if( sockaddr_alike((struct sockaddr *)&copy,
                            (struct sockaddr *)sockaddr_IPv4_2),
                 "copy failed");


}
Exemplo n.º 5
0
END_TEST



START_TEST (sockaddr_IPv6_setPort)
{
    struct sockaddr_storage ip;
    sockaddr_initFromString( (struct sockaddr *)&ip, ipv6_1_noport_str );

    sockaddr_setPort( (struct sockaddr *)&ip, 3456 );

    fail_unless( sockaddr_alike((struct sockaddr *)&ip,
                                (struct sockaddr *)sockaddr_IPv6_1),
                 "setPort failed");

    sockaddr_setPort( (struct sockaddr *)&ip, 1111 );

    fail_if( sockaddr_alike((struct sockaddr *)&ip,
                            (struct sockaddr *)sockaddr_IPv6_1),
                 "setPort failed");


}
Exemplo n.º 6
0
END_TEST


START_TEST (response_decode_IPv6)
{
    StunMessage stunMsg;
    struct sockaddr_storage a;
    struct sockaddr_storage b;

    sockaddr_initFromString((struct sockaddr*)&b, "[2001:db8:1234:5678:11:2233:4455:6677]:32853");

    

    fail_unless( stunlib_DecodeMessage( respv6,
                                        96,
                                        &stunMsg,
                                        NULL,
                                        NULL ));
    
    fail_unless(  stunlib_checkIntegrity(respv6,
                                         96,
                                         &stunMsg,
                                         password,
                                         sizeof(password)) );


    fail_unless ( 0 == memcmp(&stunMsg.msgHdr.id.octet,&idOctet,12));

    fail_unless( stunMsg.msgHdr.msgType == STUN_MSG_BindResponseMsg );

    fail_unless( stunMsg.hasXorMappedAddress );
    
    sockaddr_initFromIPv6Int((struct sockaddr_in6 *)&a,
                             stunMsg.xorMappedAddress.addr.v6.addr, 
                             htons(stunMsg.xorMappedAddress.addr.v6.port));
    
    fail_unless( sockaddr_alike((struct sockaddr *)&a,
                                (struct sockaddr *)&b) );
    
    fail_unless( stunMsg.xorMappedAddress.addr.v6.port == port );

    fail_unless( stunMsg.hasSoftware);
    fail_unless( strncmp( stunMsg.software.value,
                          software_resp,
                          max(stunMsg.software.sizeValue,sizeof(software_resp)) )==0 );
}
Exemplo n.º 7
0
CTEST(stuntrace, run_IPv4_Stunresp_max_ttl)
{
  int               someData = 3;
  STUN_CLIENT_DATA* clientData;

  struct sockaddr_storage localAddr, remoteAddr, hop1Addr;
  int                     sockfd = 4;

  sockaddr_initFromString( (struct sockaddr*)&remoteAddr,
                           "193.200.93.152:45674" );

  sockaddr_initFromString( (struct sockaddr*)&localAddr,
                           "192.168.1.34:45674" );

  StunClient_Alloc(&clientData);


  int len = StunTrace_startTrace(clientData,
                                 &someData,
                                 (const struct sockaddr*)&remoteAddr,
                                 (const struct sockaddr*)&localAddr,
                                 sockfd,
                                 "test",
                                 "tset",
                                 1,
                                 StunTraceCallBack,
                                 sendPacket);
  /* First alive probe */
  ASSERT_TRUE(len != 0);
  ASSERT_TRUE(LastTTL == 40);
  StunMessage m;
  memset( &m, 0, sizeof(m) );
  memcpy( &m.msgHdr.id,     &LastTransId, STUN_MSG_ID_SIZE);
  memcpy( &m.msgHdr.cookie, StunCookie,   sizeof(m.msgHdr.cookie) );
  m.msgHdr.msgType                = STUN_MSG_BindResponseMsg;
  m.hasXorMappedAddress           = true;
  m.xorMappedAddress.familyType   = STUN_ADDR_IPv4Family;
  m.xorMappedAddress.addr.v4.addr = test_addr_ipv4;
  m.xorMappedAddress.addr.v4.port = test_port_ipv4;

  StunClient_HandleIncResp(clientData,
                           &m,
                           NULL);

  /*Timeout is roughtly 160*50 ms*/
  for (int i = 0; i < 160 * 38; i++)
  {
    StunClient_HandleTick(clientData, 50);
  }

  /* First hop.. */
  ASSERT_TRUE(LastTTL == 39);
  sockaddr_initFromString( (struct sockaddr*)&hop1Addr,
                           "192.168.1.1:45674" );
  StunClient_HandleICMP(clientData,
                        (struct sockaddr*)&hop1Addr,
                        11);
  ASSERT_TRUE( sockaddr_alike( (struct sockaddr*)&LastHopAddr,
                               (struct sockaddr*)&hop1Addr ) );

  ASSERT_TRUE( Done);
  ASSERT_TRUE( EndOfTrace);

}
Exemplo n.º 8
0
CTEST(stuntrace, run_IPv4_Stunresp_dead)
{
  int               someData = 3;
  STUN_CLIENT_DATA* clientData;

  struct sockaddr_storage localAddr, remoteAddr, hop1Addr;
  int                     sockfd = 4;

  sockaddr_initFromString( (struct sockaddr*)&remoteAddr,
                           "193.200.93.152:45674" );

  sockaddr_initFromString( (struct sockaddr*)&localAddr,
                           "192.168.1.34:45674" );

  StunClient_Alloc(&clientData);


  StunTrace_startTrace(clientData,
                       &someData,
                       (const struct sockaddr*)&remoteAddr,
                       (const struct sockaddr*)&localAddr,
                       sockfd,
                       "test",
                       "tset",
                       1,
                       StunTraceCallBack,
                       sendPacket);

  /*Timeout is roughtly 160*50 ms*/
  for (int i = 0; i < 160; i++)
  {
    StunClient_HandleTick(clientData, 50);
  }

  /* First hop.. */
  ASSERT_TRUE(LastTTL == 1);
  sockaddr_initFromString( (struct sockaddr*)&hop1Addr,
                           "192.168.1.1:45674" );
  StunClient_HandleICMP(clientData,
                        (struct sockaddr*)&hop1Addr,
                        11);
  ASSERT_TRUE( sockaddr_alike( (struct sockaddr*)&LastHopAddr,
                               (struct sockaddr*)&hop1Addr ) );

  ASSERT_TRUE( LastTTL == 2);

  for (int i = 0; i < 160; i++)
  {
    StunClient_HandleTick(clientData, 50);
  }
  ASSERT_TRUE(LastTTL == 3);

  for (int i = 0; i < 160; i++)
  {
    StunClient_HandleTick(clientData, 50);
  }
  ASSERT_TRUE(LastTTL == 4);

  for (int i = 0; i < 160; i++)
  {
    StunClient_HandleTick(clientData, 50);
  }
  ASSERT_TRUE(LastTTL == 5);

  for (int i = 0; i < 160; i++)
  {
    StunClient_HandleTick(clientData, 50);
  }
  ASSERT_TRUE(LastTTL == 5);

  ASSERT_TRUE(Done);
  ASSERT_TRUE(EndOfTrace);
}
Exemplo n.º 9
0
CTEST(stuntrace, no_answer_recurring_IPv4)
{
  int               someData = 3;
  STUN_CLIENT_DATA* clientData;

  struct sockaddr_storage localAddr, remoteAddr, hop1Addr, hop2Addr;
  int                     sockfd = 4;

  sockaddr_initFromString( (struct sockaddr*)&remoteAddr,
                           "193.200.93.152:45674" );

  sockaddr_initFromString( (struct sockaddr*)&localAddr,
                           "192.168.1.34:45674" );

  StunClient_Alloc(&clientData);


  int len = StunTrace_startTrace(clientData,
                                 &someData,
                                 (const struct sockaddr*)&remoteAddr,
                                 (const struct sockaddr*)&localAddr,
                                 sockfd,
                                 "test",
                                 "tset",
                                 2,
                                 StunTraceCallBack,
                                 sendPacket);
  ASSERT_TRUE(len != 0);

  StunClient_HandleICMP(clientData,
                        (struct sockaddr*)&remoteAddr,
                        3);

  /* HOP 1 Answer */
  ASSERT_TRUE(LastTTL == 1);

  sockaddr_initFromString( (struct sockaddr*)&hop1Addr,
                           "192.168.1.1:45674" );
  StunClient_HandleICMP(clientData,
                        (struct sockaddr*)&hop1Addr,
                        11);
  ASSERT_FALSE(Done);
  ASSERT_FALSE(EndOfTrace);

  ASSERT_TRUE( sockaddr_alike( (struct sockaddr*)&LastHopAddr,
                               (struct sockaddr*)&hop1Addr ) );
  /* HOP 2 No Answer */
  ASSERT_TRUE( LastTTL == 2);


  ASSERT_TRUE( LastTTL == 2);
  /*Timeout is roughtly 160*50 ms*/
  for (int i = 0; i < 160; i++)
  {
    StunClient_HandleTick(clientData, 50);
  }
  ASSERT_FALSE(Done);
  ASSERT_FALSE(EndOfTrace);

  /* HOP 3 Answer */
  ASSERT_TRUE(LastTTL == 3);

  sockaddr_initFromString( (struct sockaddr*)&hop2Addr,
                           "193.200.93.152:45674" );

  StunClient_HandleICMP(clientData,
                        (struct sockaddr*)&hop2Addr,
                        3);

  ASSERT_TRUE( sockaddr_alike( (struct sockaddr*)&LastHopAddr,
                               (struct sockaddr*)&hop2Addr ) );

  ASSERT_FALSE(Done);
  ASSERT_TRUE(EndOfTrace);

  /* HOP 1 Answer */
  ASSERT_TRUE(LastTTL == 1);

  sockaddr_initFromString( (struct sockaddr*)&hop1Addr,
                           "192.168.1.1:45674" );
  StunClient_HandleICMP(clientData,
                        (struct sockaddr*)&hop1Addr,
                        11);
  ASSERT_FALSE(Done);
  ASSERT_FALSE(EndOfTrace);

  ASSERT_TRUE( sockaddr_alike( (struct sockaddr*)&LastHopAddr,
                               (struct sockaddr*)&hop1Addr ) );


  /* HOP 3 Answer */
  ASSERT_TRUE(LastTTL == 3);

  sockaddr_initFromString( (struct sockaddr*)&hop2Addr,
                           "193.200.93.152:45674" );

  StunClient_HandleICMP(clientData,
                        (struct sockaddr*)&hop2Addr,
                        3);

  ASSERT_TRUE( sockaddr_alike( (struct sockaddr*)&LastHopAddr,
                               (struct sockaddr*)&hop2Addr ) );

  ASSERT_TRUE( Done);
  ASSERT_TRUE( EndOfTrace);

}
Exemplo n.º 10
0
CTEST(stuntrace, recurring_IPv4)
{
  int               someData = 3;
  STUN_CLIENT_DATA* clientData;

  struct sockaddr_storage localAddr, remoteAddr, hop1Addr, hop2Addr;
  int                     sockfd = 4;

  sockaddr_initFromString( (struct sockaddr*)&remoteAddr,
                           "193.200.93.152:45674" );

  sockaddr_initFromString( (struct sockaddr*)&localAddr,
                           "192.168.1.34:45674" );

  StunClient_Alloc(&clientData);


  int len = StunTrace_startTrace(clientData,
                                 &someData,
                                 (const struct sockaddr*)&remoteAddr,
                                 (const struct sockaddr*)&localAddr,
                                 sockfd,
                                 "test",
                                 "tset",
                                 2,
                                 StunTraceCallBack,
                                 sendPacket);
  ASSERT_TRUE(len != 0);
  ASSERT_TRUE(LastTTL == 40);

  StunClient_HandleICMP(clientData,
                        (struct sockaddr*)&remoteAddr,
                        3);

  sockaddr_initFromString( (struct sockaddr*)&hop1Addr,
                           "192.168.1.1:45674" );
  StunClient_HandleICMP(clientData,
                        (struct sockaddr*)&hop1Addr,
                        11);
  ASSERT_FALSE(Done);
  ASSERT_FALSE(EndOfTrace);

  ASSERT_TRUE( sockaddr_alike( (struct sockaddr*)&LastHopAddr,
                               (struct sockaddr*)&hop1Addr ) );

  ASSERT_TRUE( LastTTL == 2);

  sockaddr_initFromString( (struct sockaddr*)&hop2Addr,
                           "193.200.93.152:45674" );

  StunClient_HandleICMP(clientData,
                        (struct sockaddr*)&hop2Addr,
                        3);
  ASSERT_TRUE( sockaddr_alike( (struct sockaddr*)&LastHopAddr,
                               (struct sockaddr*)&hop2Addr ) );
  ASSERT_FALSE(Done);
  ASSERT_TRUE(EndOfTrace);

  ASSERT_TRUE(LastTTL == 1);
  StunClient_HandleICMP(clientData,
                        (struct sockaddr*)&hop1Addr,
                        11);
  ASSERT_FALSE(Done);
  ASSERT_FALSE(EndOfTrace);

  ASSERT_TRUE(LastTTL == 2);

  StunClient_HandleICMP(clientData,
                        (struct sockaddr*)&hop2Addr,
                        3);
  ASSERT_TRUE( sockaddr_alike( (struct sockaddr*)&LastHopAddr,
                               (struct sockaddr*)&hop2Addr ) );

  ASSERT_TRUE( Done);
  ASSERT_TRUE( EndOfTrace);
}