// File: /workspace/github_c_makefile_star2_O0/bloomsource[P]dns_update/dns.c
// Function: main
int main( int argc, char* argv[] )
{
    int rc;
    struct pollfd pfds[2];
    char buf[1024];
    char ip[16];
    int  port;
    
    
    strcpy( log_file, "dns.log" );
    
    if( argc < 3 )
    {
        printf( "usage:dns_srv port auth_key [user]\n" );
        return 1;
    }
    
    cmd_port = atoi( argv[1] );
    snprintf( auth_key, sizeof(auth_key), "%s", argv[2] );
    
    dns_fd = udp_listen( NULL, DNS_PORT );
    if( dns_fd == -1 )
    {
        printf( "udp listen on dns port[%d] failed! err:%s\n", DNS_PORT, ERR );
        write_log( "[ERR] udp listen on dns port[%d] failed! err:%s", DNS_PORT, ERR );
        return 1;
    }
    
    cmd_fd = udp_listen( NULL, cmd_port );
    if( dns_fd == -1 )
    {
        printf( "udp listen on dns port[%d] failed! err:%s\n", cmd_port, ERR );
        write_log( "[ERR] udp listen on dns port[%d] failed! err:%s", cmd_port, ERR );
        return 1;
    }
    
    if( argc > 3 )
    {
        if( change_process_user( argv[3] ) )
        {
            printf( "process switch to user '%s' failed!\n", argv[3] );
            write_log( "[ERR] process switch to user '%s' failed!", argv[3] );
            return 1;
        }
    }
    
    signal( SIGINT, sigproc );
    signal( SIGTERM,sigproc );
    
    printf( "dns start up ok!\n" );
    write_log( "dns start up ok!" );
    write_log( "pid: %d", getpid() );
    
    rbtree_init( &domains, domain_node_cmp, domain_value_cmp, domain_node_swap );
    
    
    while( run )
    {
        pfds[0].fd = dns_fd;
        pfds[0].events = POLLIN;
        pfds[0].revents = 0;
        
        pfds[1].fd = cmd_fd;
        pfds[1].events = POLLIN;
        pfds[1].revents = 0;
        
        rc = poll( pfds, 2, 1000 );
        if( rc <= 0 )
            continue;
        
        if( pfds[0].revents )
        {
            rc = udp_recv( dns_fd, buf, sizeof(buf), ip, &port );
            if( rc > 0 )
            {
                proc_dns_query( buf, rc, ip, port );
            }
        }
        
        if( pfds[1].revents )
        {
            rc = udp_recv( cmd_fd, buf, sizeof(buf)-1, ip, &port );
            if( rc > 0 )
            {
                buf[rc] = 0;
                proc_cmd( buf, rc, ip, port );
            }
            
            
            
        }
        
        
    }
    
    write_log( "[WRN] dns stop." );
    
    return 0;
    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x450, %rsp            # imm = 0x450
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0x151c0(%rip), %rdi     # 0x17610
leaq 0xcbad(%rip), %rsi      # 0xf004
callq 0x2060
cmpl $0x3, -0x8(%rbp)
jge 0x247c
leaq 0xcba3(%rip), %rdi      # 0xf00c
movb $0x0, %al
callq 0x2120
movl $0x1, -0x4(%rbp)
jmp 0x279b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x22b0
movl %eax, %ecx
leaq 0x15252(%rip), %rax     # 0x176e4
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
leaq 0x1524d(%rip), %rdi     # 0x176f0
movl $0x64, %esi
leaq 0xd0af(%rip), %rdx      # 0xf55e
movb $0x0, %al
callq 0x2130
xorl %eax, %eax
movl %eax, %edi
movl $0x35, %esi
callq 0x38a0
movl %eax, 0x1510e(%rip)     # 0x175d8
cmpl $-0x1, 0x15107(%rip)    # 0x175d8
jne 0x2523
callq 0x2040
movl (%rax), %edi
callq 0x22f0
movq %rax, %rdx
leaq 0xcb47(%rip), %rdi      # 0xf030
movl $0x35, %esi
movb $0x0, %al
callq 0x2120
callq 0x2040
movl (%rax), %edi
callq 0x22f0
movq %rax, %rdx
leaq 0xcb50(%rip), %rdi      # 0xf05b
movl $0x35, %esi
movb $0x0, %al
callq 0x3b40
movl $0x1, -0x4(%rbp)
jmp 0x279b
leaq 0x151ba(%rip), %rax     # 0x176e4
movl (%rax), %esi
xorl %eax, %eax
movl %eax, %edi
callq 0x38a0
movl %eax, 0x150a1(%rip)     # 0x175dc
cmpl $-0x1, 0x15096(%rip)    # 0x175d8
jne 0x25b4
leaq 0x15199(%rip), %rax     # 0x176e4
movl (%rax), %eax
movl %eax, -0x44c(%rbp)
callq 0x2040
movl (%rax), %edi
callq 0x22f0
movl -0x44c(%rbp), %esi
movq %rax, %rdx
leaq 0xcac1(%rip), %rdi      # 0xf030
movb $0x0, %al
callq 0x2120
leaq 0x15167(%rip), %rax     # 0x176e4
movl (%rax), %eax
movl %eax, -0x448(%rbp)
callq 0x2040
movl (%rax), %edi
callq 0x22f0
movl -0x448(%rbp), %esi
movq %rax, %rdx
leaq 0xcaba(%rip), %rdi      # 0xf05b
movb $0x0, %al
callq 0x3b40
movl $0x1, -0x4(%rbp)
jmp 0x279b
cmpl $0x3, -0x8(%rbp)
jle 0x2606
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x4140
cmpl $0x0, %eax
je 0x2604
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
leaq 0xcab0(%rip), %rdi      # 0xf08b
movb $0x0, %al
callq 0x2120
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
leaq 0xcabf(%rip), %rdi      # 0xf0b0
movb $0x0, %al
callq 0x3b40
movl $0x1, -0x4(%rbp)
jmp 0x279b
jmp 0x2606
movl $0x2, %edi
leaq 0x19e(%rip), %rsi       # 0x27b0
callq 0x21a0
movl $0xf, %edi
leaq 0x18d(%rip), %rsi       # 0x27b0
callq 0x21a0
leaq 0xcaab(%rip), %rdi      # 0xf0da
movb $0x0, %al
callq 0x2120
leaq 0xcaaf(%rip), %rdi      # 0xf0ec
movb $0x0, %al
callq 0x3b40
callq 0x20c0
movl %eax, %esi
leaq 0xcaab(%rip), %rdi      # 0xf0fd
movb $0x0, %al
callq 0x3b40
leaq 0x14f80(%rip), %rdi     # 0x175e0
leaq 0x189(%rip), %rsi       # 0x27f0
leaq 0x1c2(%rip), %rdx       # 0x2830
leaq 0x1fb(%rip), %rcx       # 0x2870
callq 0xb290
cmpl $0x0, 0x14b2f(%rip)     # 0x171b0
je 0x2786
movl 0x14f4b(%rip), %eax     # 0x175d8
movl %eax, -0x30(%rbp)
movw $0x1, -0x2c(%rbp)
movw $0x0, -0x2a(%rbp)
movl 0x14f3a(%rip), %eax     # 0x175dc
movl %eax, -0x28(%rbp)
movw $0x1, -0x24(%rbp)
movw $0x0, -0x22(%rbp)
leaq -0x30(%rbp), %rdi
movl $0x2, %esi
movl $0x3e8, %edx            # imm = 0x3E8
callq 0x2260
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jg 0x26cf
jmp 0x267a
cmpw $0x0, -0x2a(%rbp)
je 0x2722
movl 0x14efc(%rip), %edi     # 0x175d8
leaq -0x430(%rbp), %rsi
leaq -0x440(%rbp), %rcx
movl $0x400, %edx            # imm = 0x400
leaq -0x444(%rbp), %r8
callq 0x3a00
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0x2720
leaq -0x430(%rbp), %rdi
movl -0x14(%rbp), %esi
leaq -0x440(%rbp), %rdx
movl -0x444(%rbp), %ecx
callq 0x2960
jmp 0x2722
cmpw $0x0, -0x22(%rbp)
je 0x2781
movl 0x14ead(%rip), %edi     # 0x175dc
leaq -0x430(%rbp), %rsi
leaq -0x440(%rbp), %rcx
movl $0x3ff, %edx            # imm = 0x3FF
leaq -0x444(%rbp), %r8
callq 0x3a00
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0x277f
movslq -0x14(%rbp), %rax
movb $0x0, -0x430(%rbp,%rax)
leaq -0x430(%rbp), %rdi
movl -0x14(%rbp), %esi
leaq -0x440(%rbp), %rdx
movl -0x444(%rbp), %ecx
callq 0x2f10
jmp 0x2781
jmp 0x267a
leaq 0xc978(%rip), %rdi      # 0xf105
movb $0x0, %al
callq 0x3b40
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x450, %rsp            # imm = 0x450
popq %rbp
retq
nopw (%rax,%rax)