// File: dguglielmi[P]dlan-linux-software/tools/dlanlist.cpp
// Function: main
int main(int argc, char** argv)
{
  int result = 0;
  std::set<std::string> setIfcNames;

  for(int i = 1; i < argc; ++i)
  {
    if(argv[i][0] == '-')
      result = -1;
    else
      setIfcNames.insert(argv[i]);
  }
  
  if(result == -1)
  {
    printf("Usage: dlanlist [IFACES...]\n"
           "\n"
           "List dlan devices found on the given network interfaces,\n"
           "or on all interfaces, if none where given.\n"
           "\n");

    return result;
  }

  CPacketInterfaceLinux pktIfc(setIfcNames);
  CDlanMonitor m(pktIfc);
  CPacketTaskRunner(pktIfc, m).Run(1000, MSCounter());

  if(m.GetLocalDevices().empty())
  {
    printf("no devices found\n");
    return 1;
  }

  printf("Type    MAC address        Mbps TX/RX       Version/Product\n");
  for(CDlanLocalDeviceList::const_iterator itLocal = m.GetLocalDevices().begin();
    (itLocal != m.GetLocalDevices().end()); ++itLocal)
  {
    printf("local   %s  ---.-- / ---.--  %s\n",
      itLocal->GetAddress().ToString().c_str(),
      VersionProductString(*itLocal).c_str());
 
    for(CDlanRemoteDeviceList::const_iterator itRemote = itLocal->GetRemoteDevices().begin();
      (itRemote != itLocal->GetRemoteDevices().end()); ++itRemote)
    {
      if(itRemote->GetType() == CDlanDevice::eThunderbolt)
      {
        printf("remote  %s  %6.02f / %6.02f  %s\n",
          itRemote->GetAddress().ToString().c_str(),
          itRemote->GetTxRate(),
          itRemote->GetRxRate(),
          itRemote->GetVersion().c_str());
      }
      else
      {
        printf("remote  %s  %6.02f / ---.--  %s\n",
          itRemote->GetAddress().ToString().c_str(),
          itRemote->GetTxRate(),
          VersionProductString(*itRemote).c_str());
      }
    }
  }
  
  return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x430, %rsp            # imm = 0x430
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x5360
movl $0x1, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x49a9
movq -0x10(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x48dc
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0x4999
movq -0x10(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x388(%rbp)
leaq -0x71(%rbp), %rdi
movq %rdi, -0x380(%rbp)
callq 0x4540
movq -0x388(%rbp), %rsi
movq -0x380(%rbp), %rdx
leaq -0x70(%rbp), %rdi
callq 0x52b0
jmp 0x4918
leaq -0x48(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x5380
movb %dl, -0x391(%rbp)
movq %rax, -0x390(%rbp)
jmp 0x4934
movb -0x391(%rbp), %al
movq -0x390(%rbp), %rcx
movq %rcx, -0x98(%rbp)
movb %al, -0x90(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x4240
leaq -0x71(%rbp), %rdi
callq 0x4380
jmp 0x4999
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x498b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x4240
leaq -0x71(%rbp), %rdi
callq 0x4380
jmp 0x50f2
jmp 0x499b
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x48b0
cmpl $-0x1, -0x14(%rbp)
jne 0x49e8
leaq 0x31672(%rip), %rdi     # 0x36028
xorl %eax, %eax
callq 0x4060
jmp 0x49bf
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x9c(%rbp)
jmp 0x50dd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x50f2
leaq -0x150(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x31190
jmp 0x49fa
leaq 0x3178f(%rip), %rcx     # 0x36190
leaq -0x228(%rbp), %rdi
leaq -0x150(%rbp), %rsi
movl $0x3f, %edx
callq 0x53d0
jmp 0x4a1b
leaq -0x238(%rbp), %rdi
leaq -0x150(%rbp), %rsi
leaq -0x228(%rbp), %rdx
callq 0x54f0
jmp 0x4a37
leaq -0x238(%rbp), %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x5520
jmp 0x4a4a
leaq -0x228(%rbp), %rdi
callq 0x5600
movq %rax, -0x3a0(%rbp)
jmp 0x4a5f
movq -0x3a0(%rbp), %rdi
callq 0x5620
testb $0x1, %al
jne 0x4a71
jmp 0x4abf
leaq 0x31633(%rip), %rdi     # 0x360ab
xorl %eax, %eax
callq 0x4060
jmp 0x4a81
movl $0x1, -0x4(%rbp)
movl $0x1, -0x9c(%rbp)
jmp 0x50a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x50cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x50c3
leaq 0x315f7(%rip), %rdi     # 0x360bd
xorl %eax, %eax
callq 0x4060
jmp 0x4acf
leaq -0x228(%rbp), %rdi
callq 0x5600
movq %rax, -0x3a8(%rbp)
jmp 0x4ae4
movq -0x3a8(%rbp), %rdi
callq 0x5640
movq %rax, -0x248(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x5600
movq %rax, -0x3b0(%rbp)
jmp 0x4b0c
movq -0x3b0(%rbp), %rdi
callq 0x56a0
movq %rax, -0x250(%rbp)
leaq -0x248(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x5670
testb $0x1, %al
jne 0x4b3b
jmp 0x5099
leaq -0x248(%rbp), %rdi
callq 0x56d0
movq %rax, %rdi
callq 0x5700
movq %rax, -0x3b8(%rbp)
jmp 0x4b58
leaq -0x291(%rbp), %rdi
movq %rdi, -0x3c0(%rbp)
callq 0x4540
movq -0x3c0(%rbp), %rdx
leaq 0x315a2(%rip), %rsi     # 0x3611b
leaq -0x290(%rbp), %rdi
callq 0x52b0
jmp 0x4b87
movq -0x3b8(%rbp), %rsi
leaq -0x270(%rbp), %rdi
leaq -0x290(%rbp), %rdx
callq 0x30d30
jmp 0x4ba3
leaq -0x270(%rbp), %rdi
callq 0x4170
movq %rax, -0x3c8(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x5710
movq %rax, %rsi
leaq -0x2b8(%rbp), %rdi
callq 0x4710
jmp 0x4bd3
leaq -0x2b8(%rbp), %rdi
callq 0x4170
movq -0x3c8(%rbp), %rsi
movq %rax, %rdx
leaq 0x3150a(%rip), %rdi     # 0x360fa
xorl %eax, %eax
callq 0x4060
jmp 0x4bf9
leaq -0x2b8(%rbp), %rdi
callq 0x4240
leaq -0x270(%rbp), %rdi
callq 0x4240
leaq -0x290(%rbp), %rdi
callq 0x4240
leaq -0x291(%rbp), %rdi
callq 0x4380
leaq -0x248(%rbp), %rdi
callq 0x56d0
movq %rax, %rdi
callq 0x5730
movq %rax, -0x3d0(%rbp)
jmp 0x4c46
movq -0x3d0(%rbp), %rdi
callq 0x5750
movq %rax, -0x2c0(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x56d0
movq %rax, %rdi
callq 0x5730
movq %rax, -0x3d8(%rbp)
jmp 0x4c76
movq -0x3d8(%rbp), %rdi
callq 0x57b0
movq %rax, -0x2c8(%rbp)
leaq -0x2c0(%rbp), %rdi
leaq -0x2c8(%rbp), %rsi
callq 0x5780
testb $0x1, %al
jne 0x4ca5
jmp 0x5086
leaq -0x2c0(%rbp), %rdi
callq 0x57e0
movq %rax, %rdi
callq 0x5180
movl %eax, -0x3dc(%rbp)
jmp 0x4cc1
movl -0x3dc(%rbp), %eax
cmpl $0x2, %eax
jne 0x4ee2
leaq -0x2c0(%rbp), %rdi
callq 0x57e0
movq %rax, %rdi
callq 0x5700
movq %rax, -0x3e8(%rbp)
jmp 0x4ced
leaq -0x309(%rbp), %rdi
movq %rdi, -0x3f0(%rbp)
callq 0x4540
movq -0x3f0(%rbp), %rdx
leaq 0x3140d(%rip), %rsi     # 0x3611b
leaq -0x308(%rbp), %rdi
callq 0x52b0
jmp 0x4d1c
movq -0x3e8(%rbp), %rsi
leaq -0x2e8(%rbp), %rdi
leaq -0x308(%rbp), %rdx
callq 0x30d30
jmp 0x4d38
leaq -0x2e8(%rbp), %rdi
callq 0x4170
movq %rax, -0x400(%rbp)
leaq -0x2c0(%rbp), %rdi
callq 0x57e0
movq %rax, %rdi
addq $0x90, %rdi
callq 0x5810
movsd %xmm0, -0x3f8(%rbp)
jmp 0x4d70
leaq -0x2c0(%rbp), %rdi
callq 0x57e0
movq %rax, %rdi
addq $0x90, %rdi
callq 0x5830
movsd %xmm0, -0x408(%rbp)
jmp 0x4d95
leaq -0x2c0(%rbp), %rdi
callq 0x57e0
movq %rax, %rdi
callq 0x5270
movq %rax, -0x410(%rbp)
jmp 0x4db2
movq -0x410(%rbp), %rdi
callq 0x4170
movq -0x400(%rbp), %rsi
movsd -0x3f8(%rbp), %xmm0
movsd -0x408(%rbp), %xmm1
movq %rax, %rdx
leaq 0x3133e(%rip), %rdi     # 0x3611d
movb $0x2, %al
callq 0x4060
jmp 0x4de8
leaq -0x2e8(%rbp), %rdi
callq 0x4240
leaq -0x308(%rbp), %rdi
callq 0x4240
leaq -0x309(%rbp), %rdi
callq 0x4380
jmp 0x5073
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x4e77
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x4e6b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x4e5f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x2b8(%rbp), %rdi
callq 0x4240
leaq -0x270(%rbp), %rdi
callq 0x4240
leaq -0x290(%rbp), %rdi
callq 0x4240
leaq -0x291(%rbp), %rdi
callq 0x4380
jmp 0x50c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x4ed1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x4ec5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x2e8(%rbp), %rdi
callq 0x4240
leaq -0x308(%rbp), %rdi
callq 0x4240
leaq -0x309(%rbp), %rdi
callq 0x4380
jmp 0x50c3
leaq -0x2c0(%rbp), %rdi
callq 0x57e0
movq %rax, %rdi
callq 0x5700
movq %rax, -0x418(%rbp)
jmp 0x4eff
leaq -0x351(%rbp), %rdi
movq %rdi, -0x420(%rbp)
callq 0x4540
movq -0x420(%rbp), %rdx
leaq 0x311fb(%rip), %rsi     # 0x3611b
leaq -0x350(%rbp), %rdi
callq 0x52b0
jmp 0x4f2e
movq -0x418(%rbp), %rsi
leaq -0x330(%rbp), %rdi
leaq -0x350(%rbp), %rdx
callq 0x30d30
jmp 0x4f4a
leaq -0x330(%rbp), %rdi
callq 0x4170
movq %rax, -0x430(%rbp)
leaq -0x2c0(%rbp), %rdi
callq 0x57e0
movq %rax, %rdi
addq $0x90, %rdi
callq 0x5810
movsd %xmm0, -0x428(%rbp)
jmp 0x4f82
leaq -0x2c0(%rbp), %rdi
callq 0x5850
movq %rax, %rsi
leaq -0x378(%rbp), %rdi
callq 0x4710
jmp 0x4f9f
leaq -0x378(%rbp), %rdi
callq 0x4170
movq -0x430(%rbp), %rsi
movsd -0x428(%rbp), %xmm0
movq %rax, %rdx
leaq 0x3117a(%rip), %rdi     # 0x3613e
movb $0x1, %al
callq 0x4060
jmp 0x4fcd
leaq -0x378(%rbp), %rdi
callq 0x4240
leaq -0x330(%rbp), %rdi
callq 0x4240
leaq -0x350(%rbp), %rdi
callq 0x4240
leaq -0x351(%rbp), %rdi
callq 0x4380
jmp 0x5073
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x5065
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x5059
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x504d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x378(%rbp), %rdi
callq 0x4240
leaq -0x330(%rbp), %rdi
callq 0x4240
leaq -0x350(%rbp), %rdi
callq 0x4240
leaq -0x351(%rbp), %rdi
callq 0x4380
jmp 0x50c3
jmp 0x5075
leaq -0x2c0(%rbp), %rdi
callq 0x5870
jmp 0x4c59
jmp 0x5088
leaq -0x248(%rbp), %rdi
callq 0x5890
jmp 0x4af7
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x9c(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x15a80
leaq -0x150(%rbp), %rdi
callq 0x31290
jmp 0x50dd
leaq -0x228(%rbp), %rdi
callq 0x15a80
leaq -0x150(%rbp), %rdi
callq 0x31290
jmp 0x50f2
leaq -0x48(%rbp), %rdi
callq 0x58b0
movl -0x4(%rbp), %eax
addq $0x430, %rsp            # imm = 0x430
popq %rbp
retq
leaq -0x48(%rbp), %rdi
callq 0x58b0
movq -0x80(%rbp), %rdi
callq 0x4530
nopw %cs:(%rax,%rax)