// File: /workspace/github_c_makefile_star2_O0/niuyuling[P]CProxy/httpudp.c
// Function: recvClient
static int recvClient(info_t * client)
{
    static char control[1024];
    struct msghdr msg;
    struct iovec io;
    struct cmsghdr *cmsg;

    msg.msg_name = &client->inaddr;
    msg.msg_namelen = sizeof(client->inaddr);
    msg.msg_iov = &io;
    msg.msg_iovlen = 1;
    msg.msg_control = control;
    msg.msg_controllen = sizeof(control);
    io.iov_base = client->client_data + sizeof(struct sockaddr_in) + sizeof(uint16_t);
    io.iov_len = CLIENT_BUFFER_SIZE;
    client->client_data_len = recvmsg(global.udp_listen_fd, &msg, 0);
    if (client->client_data_len <= 0) {
        //perror("recvmsg()");
        return 1;
    }
    /* 取得客户端目标地址 */
    for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg))
        if (cmsg->cmsg_level == SOL_IP && cmsg->cmsg_type == IP_ORIGDSTADDR && cmsg->cmsg_len >= CMSG_LEN(sizeof(client->toaddr))) {
            memcpy(&client->toaddr, CMSG_DATA(cmsg), sizeof(client->toaddr));
            break;
        }
    if (cmsg == NULL)
        return 1;
    /*
       printf("src ip: [%s], port: [%d]\n", inet_ntoa(client->inaddr.sin_addr), ntohs(client->inaddr.sin_port));
       printf("dst ip: [%s], port: [%d]\n", inet_ntoa(client->toaddr.sin_addr), ntohs(client->toaddr.sin_port));
     */
    //printf("client len: %d\n", client->client_data_len);
    //复制udp长度和原始目标地址
    memcpy(client->client_data, &client->toaddr, sizeof(struct sockaddr_in));
    memcpy(client->client_data + sizeof(struct sockaddr_in), &client->client_data_len, sizeof(uint16_t));
    client->client_data_len += sizeof(uint16_t) + sizeof(struct sockaddr_in);
    if (udp.encodeCode)
        dataEncode(client->client_data, client->client_data_len, udp.encodeCode);
    if (udp.httpsProxy_encodeCode)
        dataEncode(client->client_data, client->client_data_len, udp.httpsProxy_encodeCode);

    client->next = NULL;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0x10014, %rax          # imm = 0x10014
movq %rax, -0x48(%rbp)
movl $0x10, -0x40(%rbp)
leaq -0x58(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x1, -0x30(%rbp)
leaq 0x206d2e8(%rip), %rax   # 0x20769f0
movq %rax, -0x28(%rbp)
movq $0x400, -0x20(%rbp)     # imm = 0x400
movq -0x10(%rbp), %rax
addq $0x10, %rax
addq $0x2, %rax
movq %rax, -0x58(%rbp)
movq $0xffff, -0x50(%rbp)    # imm = 0xFFFF
leaq 0x12c9d(%rip), %rax     # 0x1c3d0
movl 0x8(%rax), %edi
leaq -0x48(%rbp), %rsi
xorl %edx, %edx
callq 0x23f0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10048(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10048(%rax)
jg 0x9766
movl $0x1, -0x4(%rbp)
jmp 0x9893
cmpq $0x10, -0x20(%rbp)
jb 0x9777
movq -0x28(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x977f
xorl %eax, %eax
movq %rax, -0x68(%rbp)
jmp 0x977f
movq -0x68(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x97e1
movq -0x60(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x97cc
movq -0x60(%rbp), %rax
cmpl $0x14, 0xc(%rax)
jne 0x97cc
movq -0x60(%rbp), %rax
cmpq $0x20, (%rax)
jb 0x97cc
movq -0x10(%rbp), %rax
movq -0x60(%rbp), %rcx
movq 0x10(%rcx), %rdx
movq %rdx, 0x10024(%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x1002c(%rax)
jmp 0x97e1
jmp 0x97ce
movq -0x60(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x2510
movq %rax, -0x60(%rbp)
jmp 0x9787
cmpq $0x0, -0x60(%rbp)
jne 0x97f4
movl $0x1, -0x4(%rbp)
jmp 0x9893
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x10024(%rcx), %rdx
movq %rdx, (%rax)
movq 0x1002c(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movw 0x10048(%rcx), %cx
movw %cx, 0x10(%rax)
movq -0x10(%rbp), %rax
movslq 0x10048(%rax), %rcx
addq $0x12, %rcx
movl %ecx, 0x10048(%rax)
cmpl $0x0, 0x206d1a0(%rip)   # 0x20769e0
je 0x985b
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x10048(%rax), %esi
movl 0x206d18a(%rip), %edx   # 0x20769e0
callq 0x3e20
cmpl $0x0, 0x206d182(%rip)   # 0x20769e4
je 0x987d
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x10048(%rax), %esi
movl 0x206d16c(%rip), %edx   # 0x20769e4
callq 0x3e20
movq -0x10(%rbp), %rax
movq $0x0, 0x10038(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)