// File: /workspace/github_c_makefile_star2_O1/niuyuling[P]CProxy/httpdns.c
// Function: httpDNS_respond_client
static int8_t httpDNS_respond_client(dns_t * dns, char *rspIp)
{
    static char rsp[DNS_REQUEST_MAX_SIZE + 16];
    char *p;
    int rsp_len;

    //18: 查询资源的前(12字节)后(6字节)部分
    rsp_len = 18 + dns->host_len + (rspIp ? 16 : 0);
    //判断是否超出缓冲大小
    if (rsp_len > DNS_REQUEST_MAX_SIZE) {
        dns->query_type = 0;
        return 1;
    }
    /* dns ID */
    memcpy(rsp, dns->dns_req, 2);
    /* 问题数 */
    rsp[4] = 0;
    rsp[5] = 1;
    /* 资源记录数 */
    rsp[6] = 0;
    rsp[7] = 0;
    /* 授权资源记录数 */
    rsp[8] = 0;
    rsp[9] = 0;
    /* 额外资源记录数 */
    rsp[10] = 0;
    rsp[11] = 0;
    memcpy(rsp + 12, dns->dns_req + 12, dns->host_len + 6);
    /* 如果有回应内容(资源记录) */
    if (rspIp) {
        p = rsp + 18 + dns->host_len;
        /* 资源记录数+1 */
        rsp[7]++;
        /* 成功标志 */
        rsp[2] = (char)133;
        rsp[3] = (char)128;
        /* 指向主机域名 */
        p[0] = (char)192;
        p[1] = 12;
        /* 回应类型 */
        p[2] = 0;
        p[3] = dns->query_type;
        /* 区域类别 */
        p[4] = 0;
        p[5] = 1;
        /* 生存时间 (1 ora) */
        p[6] = 0;
        p[7] = 0;
        p[8] = 14;
        p[9] = 16;
        /* 回应长度 */
        p[10] = 0;
        p[11] = 4;
        memcpy(p + 12, rspIp, 4);
    } else {
        /* 失败标志 */
        rsp[2] = (char)129;
        rsp[3] = (char)130;
    }

    //因为UDP是无连接协议，所以不做返回值判断
    sendto(global.dns_listen_fd, rsp, rsp_len, 0, (struct sockaddr *)&dns->src_addr, sizeof(struct sockaddr_in));
    dns->query_type = 0;        //表示结构体空闲
    if (cfp && rspIp)
        cache_record(dns->dns_req, dns->dns_req_len, rsp, rsp_len);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movzbl 0x23b(%rdi), %r15d
andl $0x7f, %r15d
xorl %r12d, %r12d
testq %rsi, %rsi
setne %r12b
shll $0x4, %r12d
movzwl (%rdi), %eax
movw %ax, 0x5c692(%rip)      # 0x62f00
movw $0x100, 0x5c68d(%rip)   # imm = 0x100
leaq 0xc(%rdi), %rsi
leaq 0x6(%r15), %rdx
movl $0x0, 0x5c67d(%rip)     # 0x62f06
movw $0x0, 0x5c678(%rip)     # 0x62f0a
leaq 0x5c673(%rip), %rdi     # 0x62f0c
callq 0x22d0
leal (%r15,%r12), %ebp
addl $0x12, %ebp
testq %r14, %r14
je 0x68f9
movzbl 0x23b(%rbx), %eax
andl $0x7f, %eax
leaq 0x5c645(%rip), %rcx     # 0x62f00
movb $0x1, 0x5c645(%rip)     # 0x62f07
movw $0x8085, 0x5c637(%rip)  # imm = 0x8085
movw $0xcc0, 0x12(%rax,%rcx) # imm = 0xCC0
movb $0x0, 0x14(%rax,%rcx)
movb 0x23a(%rbx), %dl
movb %dl, 0x15(%rax,%rcx)
movabsq $0x400100e00000100, %rdx # imm = 0x400100E00000100
movq %rdx, 0x16(%rax,%rcx)
movl (%r14), %edx
movl %edx, 0x1e(%rax,%rcx)
jmp 0x6902
movw $0x8281, 0x5c600(%rip)  # imm = 0x8281
leaq 0x12a67(%rip), %rax     # 0x19370
movl 0x4(%rax), %edi
movl %ebp, %edx
leaq 0x204(%rbx), %r8
leaq 0x5c5e4(%rip), %rsi     # 0x62f00
xorl %ecx, %ecx
movl $0x10, %r9d
callq 0x21c0
movb $0x0, 0x23a(%rbx)
testq %r14, %r14
je 0x695c
cmpq $0x0, 0x12d23(%rip)     # 0x19660
je 0x695c
movzwl 0x238(%rbx), %esi
leaq 0x5c5b3(%rip), %rdx     # 0x62f00
movq %rbx, %rdi
movl %ebp, %ecx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x6965
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq