// File: Distrotech[P]stund/udp.cxx
// Function: sendMessage(int, char*, int, unsigned int, unsigned short, bool)
bool 
sendMessage( Socket fd, char* buf, int l, 
             unsigned int dstIp, unsigned short dstPort,
             bool verbose)
{
   assert( fd != INVALID_SOCKET );
    
   int s;
   if ( dstPort == 0 )
   {
      // sending on a connected port 
      assert( dstIp == 0 );
		
      s = send(fd,buf,l,0);
   }
   else
   {
      assert( dstIp != 0 );
      assert( dstPort != 0 );
        
      struct sockaddr_in to;
      int toLen = sizeof(to);
      memset(&to,0,toLen);
        
      to.sin_family = AF_INET;
      to.sin_port = htons(dstPort);
      to.sin_addr.s_addr = htonl(dstIp);
        
      s = sendto(fd, buf, l, 0,(sockaddr*)&to, toLen);
   }
    
   if ( s == SOCKET_ERROR )
   {
      int e = getErrno();
      switch (e)
      {
         case ECONNREFUSED:
         case EHOSTDOWN:
         case EHOSTUNREACH:
         {
            // quietly ignore this 
         }
         break;
         case EAFNOSUPPORT:
         {
            cerr << "err EAFNOSUPPORT in send" << endl;
         }
         break;
         default:
         {
            cerr << "err " << e << " "  << strerror(e) << " in send" << endl;
         }
      }
      return false;
   }
    
   if ( s == 0 )
   {
      cerr << "no data sent in send" << endl;
      return false;
   }
    
   if ( s != l )
   {
      if (verbose)
      {
         cerr << "only " << s << " out of " << l << " bytes sent" << endl;
      }
      return false;
   }
    
   return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl %r8d, -0x4c(%rbp)
movl %ecx, %eax
movl -0x4c(%rbp), %ecx
movl %eax, -0x48(%rbp)
movl %edx, %eax
movl -0x48(%rbp), %edx
movl %eax, -0x44(%rbp)
movq %rsi, %rax
movl -0x44(%rbp), %esi
movq %rax, -0x40(%rbp)
movl %edi, %r8d
movq -0x40(%rbp), %rdi
movb %r9b, %al
movl %r8d, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movw %cx, -0x1a(%rbp)
andb $0x1, %al
movb %al, -0x1b(%rbp)
cmpl $-0x1, -0x8(%rbp)
je 0x941f
jmp 0x943e
leaq 0x209f(%rip), %rdi      # 0xb4c5
leaq 0x20ad(%rip), %rsi      # 0xb4da
movl $0xbb, %edx
leaq 0x21e7(%rip), %rcx      # 0xb620
callq 0x2140
movzwl -0x1a(%rbp), %eax
cmpl $0x0, %eax
jne 0x9488
cmpl $0x0, -0x18(%rbp)
jne 0x944f
jmp 0x946e
leaq 0x2214(%rip), %rdi      # 0xb66a
leaq 0x207d(%rip), %rsi      # 0xb4da
movl $0xc1, %edx
leaq 0x21b7(%rip), %rcx      # 0xb620
callq 0x2140
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movslq -0x14(%rbp), %rdx
xorl %ecx, %ecx
callq 0x2100
movl %eax, -0x20(%rbp)
jmp 0x952a
cmpl $0x0, -0x18(%rbp)
je 0x9490
jmp 0x94af
leaq 0x21de(%rip), %rdi      # 0xb675
leaq 0x203c(%rip), %rsi      # 0xb4da
movl $0xc7, %edx
leaq 0x2176(%rip), %rcx      # 0xb620
callq 0x2140
movzwl -0x1a(%rbp), %eax
cmpl $0x0, %eax
je 0x94ba
jmp 0x94d9
leaq 0x21bf(%rip), %rdi      # 0xb680
leaq 0x2012(%rip), %rsi      # 0xb4da
movl $0xc8, %edx
leaq 0x214c(%rip), %rcx      # 0xb620
callq 0x2140
movl $0x10, -0x34(%rbp)
movslq -0x34(%rbp), %rdx
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x2130
movw $0x2, -0x30(%rbp)
movzwl -0x1a(%rbp), %edi
callq 0x2040
movw %ax, -0x2e(%rbp)
movl -0x18(%rbp), %edi
callq 0x2170
movl %eax, -0x2c(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movslq -0x14(%rbp), %rdx
movl -0x34(%rbp), %r9d
xorl %ecx, %ecx
leaq -0x30(%rbp), %r8
callq 0x2050
movl %eax, -0x20(%rbp)
cmpl $-0x1, -0x20(%rbp)
jne 0x95eb
callq 0x8e80
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x50(%rbp)
subl $0x61, %eax
je 0x955b
jmp 0x9549
movl -0x50(%rbp), %eax
addl $-0x6f, %eax
subl $0x2, %eax
ja 0x957f
jmp 0x9556
jmp 0x95e2
movq 0x4a8e(%rip), %rdi      # 0xdff0
leaq 0x2124(%rip), %rsi      # 0xb68d
callq 0x21f0
movq %rax, %rdi
movq 0x4a48(%rip), %rsi      # 0xdfc0
callq 0x2200
jmp 0x95e2
movq 0x4a6a(%rip), %rdi      # 0xdff0
leaq 0x2119(%rip), %rsi      # 0xb6a6
callq 0x21f0
movq %rax, %rdi
movl -0x38(%rbp), %esi
callq 0x2300
movq %rax, %rdi
leaq 0xee6(%rip), %rsi       # 0xa48d
callq 0x21f0
movq %rax, -0x58(%rbp)
movl -0x38(%rbp), %edi
callq 0x20b0
movq -0x58(%rbp), %rdi
movq %rax, %rsi
callq 0x21f0
movq %rax, %rdi
leaq 0x20cf(%rip), %rsi      # 0xb69d
callq 0x21f0
movq %rax, %rdi
movq 0x49e3(%rip), %rsi      # 0xdfc0
callq 0x2200
movb $0x0, -0x1(%rbp)
jmp 0x9687
cmpl $0x0, -0x20(%rbp)
jne 0x9619
movq 0x49f8(%rip), %rdi      # 0xdff0
leaq 0x20ac(%rip), %rsi      # 0xb6ab
callq 0x21f0
movq %rax, %rdi
movq 0x49b2(%rip), %rsi      # 0xdfc0
callq 0x2200
movb $0x0, -0x1(%rbp)
jmp 0x9687
movl -0x20(%rbp), %eax
cmpl -0x14(%rbp), %eax
je 0x9683
testb $0x1, -0x1b(%rbp)
je 0x967d
movq 0x49c2(%rip), %rdi      # 0xdff0
leaq 0x208b(%rip), %rsi      # 0xb6c0
callq 0x21f0
movq %rax, %rdi
movl -0x20(%rbp), %esi
callq 0x2300
movq %rax, %rdi
leaq 0x2077(%rip), %rsi      # 0xb6c6
callq 0x21f0
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x2300
movq %rax, %rdi
leaq 0x2066(%rip), %rsi      # 0xb6cf
callq 0x21f0
movq %rax, %rdi
movq 0x4948(%rip), %rsi      # 0xdfc0
callq 0x2200
movb $0x0, -0x1(%rbp)
jmp 0x9687
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)