// File: Distrotech[P]stund/stun.cxx
// Function: stunSendTest(int, StunAddress4&, StunAtrString const&, StunAtrString const&, int, bool)
static void 
stunSendTest( Socket myFd, StunAddress4& dest, 
              const StunAtrString& username, const StunAtrString& password, 
              int testNum, bool verbose )
{ 
   assert( dest.addr != 0 );
   assert( dest.port != 0 );
	
   bool changePort=false;
   bool changeIP=false;
   bool discard=false;
	
   switch (testNum)
   {
      case 1:
      case 10:
      case 11:
         break;
      case 2:
         //changePort=true;
         changeIP=true;
         break;
      case 3:
         changePort=true;
         break;
      case 4:
         changeIP=true;
         break;
      case 5:
         discard=true;
         break;
      default:
         cerr << "Test " << testNum <<" is unkown\n";
         assert(0);
   }
	
   StunMessage req;
   memset(&req, 0, sizeof(StunMessage));
	
   stunBuildReqSimple( &req, username, 
                       changePort , changeIP , 
                       testNum );
	
   char buf[STUN_MAX_MESSAGE_SIZE];
   int len = STUN_MAX_MESSAGE_SIZE;
	
   len = stunEncodeMessage( req, buf, len, password,verbose );
	
   if ( verbose )
   {
      clog << "About to send msg of len " << len << " to " << dest << endl;
   }
	
   sendMessage( myFd, buf, len, dest.addr, dest.port, verbose );
	
   // add some delay so the packets don't get sent too quickly 
#ifdef WIN32 // !cj! TODO - should fix this up in windows
		 clock_t now = clock();
		 assert( CLOCKS_PER_SEC == 1000 );
		 while ( clock() <= now+10 ) { };
#else
		 usleep(10*1000);
#endif

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd00, %rsp            # imm = 0xD00
movb %r9b, %al
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
andb $0x1, %al
movb %al, -0x25(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x7ba2
jmp 0x7bc1
leaq 0x3332(%rip), %rdi      # 0xaedb
leaq 0x2ba5(%rip), %rsi      # 0xa755
movl $0x6c9, %edx            # imm = 0x6C9
leaq 0x37b5(%rip), %rcx      # 0xb371
callq 0x2140
movq -0x10(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x0, %eax
je 0x7bcf
jmp 0x7bee
leaq 0x3343(%rip), %rdi      # 0xaf19
leaq 0x2b78(%rip), %rsi      # 0xa755
movl $0x6ca, %edx            # imm = 0x6CA
leaq 0x3788(%rip), %rcx      # 0xb371
callq 0x2140
movb $0x0, -0x26(%rbp)
movb $0x0, -0x27(%rbp)
movb $0x0, -0x28(%rbp)
movl -0x24(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0xd00(%rbp)
subl $0xa, %eax
ja 0x7c3e
movq -0xd00(%rbp), %rax
leaq 0x27c1(%rip), %rcx      # 0xa3dc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x7c8a
movb $0x1, -0x27(%rbp)
jmp 0x7c8a
movb $0x1, -0x26(%rbp)
jmp 0x7c8a
movb $0x1, -0x27(%rbp)
jmp 0x7c8a
movb $0x1, -0x28(%rbp)
jmp 0x7c8a
movq 0x63ab(%rip), %rdi      # 0xdff0
leaq 0x3788(%rip), %rsi      # 0xb3d4
callq 0x21f0
movq %rax, %rdi
movl -0x24(%rbp), %esi
callq 0x2300
movq %rax, %rdi
leaq 0x3774(%rip), %rsi      # 0xb3da
callq 0x21f0
leaq 0x3a0c(%rip), %rdi      # 0xb67e
leaq 0x2adc(%rip), %rsi      # 0xa755
movl $0x6e5, %edx            # imm = 0x6E5
leaq 0x36ec(%rip), %rcx      # 0xb371
callq 0x2140
leaq -0x4f0(%rbp), %rdi
xorl %esi, %esi
movl $0x4c8, %edx            # imm = 0x4C8
callq 0x2130
movq -0x18(%rbp), %rsi
movb -0x26(%rbp), %cl
movb -0x27(%rbp), %al
movl -0x24(%rbp), %r8d
leaq -0x4f0(%rbp), %rdi
andb $0x1, %cl
andb $0x1, %al
movzbl %cl, %edx
movzbl %al, %ecx
callq 0x76c0
movl $0x800, -0xcf4(%rbp)    # imm = 0x800
leaq -0xcf0(%rbp), %rsi
movl -0xcf4(%rbp), %edx
movq -0x20(%rbp), %rcx
movb -0x25(%rbp), %al
leaq -0x4f0(%rbp), %rdi
andb $0x1, %al
movzbl %al, %r8d
callq 0x44c0
movl %eax, -0xcf4(%rbp)
testb $0x1, -0x25(%rbp)
je 0x7d49
movq 0x62ab(%rip), %rdi      # 0xdfb0
leaq 0x265b(%rip), %rsi      # 0xa367
callq 0x21f0
movq %rax, %rdi
movl -0xcf4(%rbp), %esi
callq 0x2300
movq %rax, %rdi
leaq 0x2658(%rip), %rsi      # 0xa381
callq 0x21f0
movq %rax, %rdi
movq -0x10(%rbp), %rsi
callq 0x4040
movq %rax, %rdi
movq 0x627c(%rip), %rsi      # 0xdfc0
callq 0x2200
movl -0x4(%rbp), %edi
leaq -0xcf0(%rbp), %rsi
movl -0xcf4(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x10(%rbp), %rax
movw (%rax), %r8w
movb -0x25(%rbp), %al
andb $0x1, %al
movzwl %r8w, %r8d
movzbl %al, %r9d
callq 0x93d0
movl $0x2710, %edi           # imm = 0x2710
callq 0x22a0
addq $0xd00, %rsp            # imm = 0xD00
popq %rbp
retq
nopl (%rax)