// File: CDISC2020[P]Projet_satellite_agile/src/ARINC/ARINC_Com.cpp
// Function: QueuingPort::QueuingPort(int, int, char*)
QueuingPort::QueuingPort (int m, int p, char* S) {

              // Parameters
                mode=m; // m=1 client, m=2 server
                cout << "Initialization in mode (O: client; 1:server) = " << mode << endl;
                port=p;
                strcpy(host_s, S);
cout << "*** TRACE : host_s = " << host_s << " S=" << S << endl;

                // Initialisation of host entry
                if ((s_h = gethostbyname(host_s)) == NULL) {
                        perror("gethostbyname");
                        exit(1);
                        } 

                // Initialisation of server address
                bzero((char *) &s_a, sizeof(s_a));
                bcopy(s_h->h_addr, (char *)&s_a.sin_addr, s_h->h_length);
                s_a.sin_family = s_h->h_addrtype;
                s_a.sin_port = port /* SERVER port */ ;

                // Creation of the Socket
                 if ((s_d = socket(AF_INET, SOCK_DGRAM, 0)) == SOCK_ERR) {
                        perror("C-> socket");
                        bye(s_d);
                }
                cout << "Socket creation... ok!" << endl;

                // Binding in server mode
                if (mode==1) { // Server mode
                        cout << "Status Server mode (bind)... " << endl;
                        if (bind(s_d, (struct sockaddr *)&s_a, sizeof(s_a)) == SOCK_ERR) { 
                        perror("S-> bind");
                        bye(s_d);
                        }
                }
                else 
                        cout << "Status Client Mode..." << endl;

        }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movl -0xc(%rbp), %ecx
movl %ecx, 0x4c0(%rax)
movq 0x7602(%rip), %rdi      # 0xafd0
leaq 0x465c(%rip), %rsi      # 0x8031
callq 0x3280
movq %rax, %rdi
movq -0x20(%rbp), %rax
movl 0x4c0(%rax), %esi
callq 0x3490
movq %rax, %rdi
movq 0x75ca(%rip), %rsi      # 0xafc0
callq 0x32b0
movq -0x20(%rbp), %rdi
movl -0x10(%rbp), %eax
movl %eax, 0x4a8(%rdi)
addq $0x428, %rdi            # imm = 0x428
movq -0x18(%rbp), %rsi
callq 0x3250
movq 0x75b1(%rip), %rdi      # 0xafd0
leaq 0x463b(%rip), %rsi      # 0x8061
callq 0x3280
movq -0x20(%rbp), %rsi
movq %rax, %rdi
addq $0x428, %rsi            # imm = 0x428
callq 0x3280
movq %rax, %rdi
leaq 0x462f(%rip), %rsi      # 0x8077
callq 0x3280
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x3280
movq %rax, %rdi
movq 0x755d(%rip), %rsi      # 0xafc0
callq 0x32b0
movq -0x20(%rbp), %rdi
addq $0x428, %rdi            # imm = 0x428
callq 0x32e0
movq -0x20(%rbp), %rcx
movq %rax, 0x4b0(%rcx)
cmpq $0x0, %rax
jne 0x3a9f
leaq 0x45eb(%rip), %rdi      # 0x807b
callq 0x3200
movl $0x1, %edi
callq 0x3310
movq -0x20(%rbp), %rdi
addq $0x408, %rdi            # imm = 0x408
movl $0x10, %esi
callq 0x34a0
movq -0x20(%rbp), %rax
movq 0x4b0(%rax), %rcx
movq 0x18(%rcx), %rcx
movq (%rcx), %rdi
movq %rax, %rsi
addq $0x408, %rsi            # imm = 0x408
addq $0x4, %rsi
movq 0x4b0(%rax), %rax
movslq 0x14(%rax), %rdx
callq 0x32f0
movq -0x20(%rbp), %rax
movq 0x4b0(%rax), %rcx
movl 0x10(%rcx), %ecx
movw %cx, 0x408(%rax)
movl 0x4a8(%rax), %ecx
movw %cx, 0x40a(%rax)
movl $0x2, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x30c0
movq -0x20(%rbp), %rcx
movl %eax, 0x404(%rcx)
cmpl $-0x1, %eax
jne 0x3b3e
leaq 0x455f(%rip), %rdi      # 0x8089
callq 0x3200
movq -0x20(%rbp), %rax
movl 0x404(%rax), %edi
callq 0x38e0
movq 0x748b(%rip), %rdi      # 0xafd0
leaq 0x4548(%rip), %rsi      # 0x8094
callq 0x3280
movq %rax, %rdi
movq 0x7465(%rip), %rsi      # 0xafc0
callq 0x32b0
movq -0x20(%rbp), %rax
cmpl $0x1, 0x4c0(%rax)
jne 0x3bcc
movq 0x745c(%rip), %rdi      # 0xafd0
leaq 0x4530(%rip), %rsi      # 0x80ab
callq 0x3280
movq %rax, %rdi
movq 0x7436(%rip), %rsi      # 0xafc0
callq 0x32b0
movq -0x20(%rbp), %rsi
movl 0x404(%rsi), %edi
addq $0x408, %rsi            # imm = 0x408
movl $0x10, %edx
callq 0x3080
cmpl $-0x1, %eax
jne 0x3bca
leaq 0x4513(%rip), %rdi      # 0x80c9
callq 0x3200
movq -0x20(%rbp), %rax
movl 0x404(%rax), %edi
callq 0x38e0
jmp 0x3bee
movq 0x73fd(%rip), %rdi      # 0xafd0
leaq 0x44f8(%rip), %rsi      # 0x80d2
callq 0x3280
movq %rax, %rdi
movq 0x73d7(%rip), %rsi      # 0xafc0
callq 0x32b0
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)