// File: Distrotech[P]stund/udp.cxx
// Function: getMessage(int, char*, int*, unsigned int*, unsigned short*, bool)
bool 
getMessage( Socket fd, char* buf, int* len,
            unsigned int* srcIp, unsigned short* srcPort,
            bool verbose)
{
   assert( fd != INVALID_SOCKET );
	
   int originalSize = *len;
   assert( originalSize > 0 );
   
   struct sockaddr_in from;
   int fromLen = sizeof(from);
	
   *len = recvfrom(fd,
                   buf,
                   originalSize,
                   0,
                   (struct sockaddr *)&from,
                   (socklen_t*)&fromLen);
	
   if ( *len == SOCKET_ERROR )
   {
      int err = getErrno();
		
      switch (err)
      {
         case ENOTSOCK:
            cerr << "Error fd not a socket" <<   endl;
            break;
         case ECONNRESET:
            cerr << "Error connection reset - host not reachable" <<   endl;
            break;
				
         default:
            cerr << "Socket Error=" << err << endl;
      }
		
      return false;
   }
	
   if ( *len < 0 )
   {
      clog << "socket closed? negative len" << endl;
      return false;
   }
    
   if ( *len == 0 )
   {
      clog << "socket closed? zero len" << endl;
      return false;
   }
    
   *srcPort = ntohs(from.sin_port);
   *srcIp = ntohl(from.sin_addr.s_addr);
	
   if ( (*len)+1 >= originalSize )
   {
      if (verbose)
      {
         clog << "Received a message that was too large" << endl;
      }
      return false;
   }
   buf[*len]=0;
    
   return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %r9b, %al
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
andb $0x1, %al
movb %al, -0x29(%rbp)
cmpl $-0x1, -0x8(%rbp)
je 0x91cb
jmp 0x91ea
leaq 0x22f3(%rip), %rdi      # 0xb4c5
leaq 0x2301(%rip), %rsi      # 0xb4da
movl $0x76, %edx
leaq 0x2331(%rip), %rcx      # 0xb516
callq 0x2140
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0x91fb
jmp 0x921a
leaq 0x2363(%rip), %rdi      # 0xb565
leaq 0x22d1(%rip), %rsi      # 0xb4da
movl $0x79, %edx
leaq 0x2301(%rip), %rcx      # 0xb516
callq 0x2140
movl $0x10, -0x44(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movslq -0x30(%rbp), %rdx
xorl %ecx, %ecx
leaq -0x40(%rbp), %r8
leaq -0x44(%rbp), %r9
callq 0x2180
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
cmpl $-0x1, (%rax)
jne 0x92ed
callq 0x8e80
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x4c(%rbp)
subl $0x58, %eax
je 0x926f
jmp 0x9265
movl -0x4c(%rbp), %eax
subl $0x68, %eax
je 0x9293
jmp 0x92b7
movq 0x4d7a(%rip), %rdi      # 0xdff0
leaq 0x22f9(%rip), %rsi      # 0xb576
callq 0x21f0
movq %rax, %rdi
movq 0x4d34(%rip), %rsi      # 0xdfc0
callq 0x2200
jmp 0x92e4
movq 0x4d56(%rip), %rdi      # 0xdff0
leaq 0x22eb(%rip), %rsi      # 0xb58c
callq 0x21f0
movq %rax, %rdi
movq 0x4d10(%rip), %rsi      # 0xdfc0
callq 0x2200
jmp 0x92e4
movq 0x4d32(%rip), %rdi      # 0xdff0
leaq 0x22f3(%rip), %rsi      # 0xb5b8
callq 0x21f0
movq %rax, %rdi
movl -0x48(%rbp), %esi
callq 0x2300
movq %rax, %rdi
movq 0x4ce1(%rip), %rsi      # 0xdfc0
callq 0x2200
movb $0x0, -0x1(%rbp)
jmp 0x93c4
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jge 0x9321
movq 0x4cb3(%rip), %rdi      # 0xdfb0
leaq 0x22c2(%rip), %rsi      # 0xb5c6
callq 0x21f0
movq %rax, %rdi
movq 0x4cad(%rip), %rsi      # 0xdfc0
callq 0x2200
movb $0x0, -0x1(%rbp)
jmp 0x93c4
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x9352
movq 0x4c7f(%rip), %rdi      # 0xdfb0
leaq 0x22aa(%rip), %rsi      # 0xb5e2
callq 0x21f0
movq %rax, %rdi
movq 0x4c79(%rip), %rsi      # 0xdfc0
callq 0x2200
movb $0x0, -0x1(%rbp)
jmp 0x93c4
movzwl -0x3e(%rbp), %edi
callq 0x2330
movw %ax, %cx
movq -0x28(%rbp), %rax
movw %cx, (%rax)
movl -0x3c(%rbp), %edi
callq 0x2250
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl (%rax), %eax
addl $0x1, %eax
cmpl -0x30(%rbp), %eax
jl 0x93b1
testb $0x1, -0x29(%rbp)
je 0x93ab
movq 0x4c20(%rip), %rdi      # 0xdfb0
leaq 0x2263(%rip), %rsi      # 0xb5fa
callq 0x21f0
movq %rax, %rdi
movq 0x4c1a(%rip), %rsi      # 0xdfc0
callq 0x2200
movb $0x0, -0x1(%rbp)
jmp 0x93c4
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movb $0x0, (%rax,%rcx)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nop