// File: lotuskip[P]yuxtapa/server/network.cpp
// Function: Network::startup()
bool Network::startup()
{
	struct addrinfo hints, *servinfo, *p;
	bzero(&hints, sizeof(hints));
	switch(Config::int_settings[Config::IS_IPV])
	{
	case 0: hints.ai_family = AF_UNSPEC; break;
	case 4: hints.ai_family = AF_INET; break;
	case 6: hints.ai_family = AF_INET6;
	}
	hints.ai_socktype = SOCK_DGRAM;
	hints.ai_flags = AI_PASSIVE; // use my IP
	int rv;
	if((rv = getaddrinfo(NULL,
		lex_cast(Config::int_settings[Config::IS_PORT]).c_str(),
		&hints, &servinfo)) != 0)
	{
		cerr << "Error in getaddrinfo: " <<  gai_strerror(rv) << endl;
		return false;
	}
	for(p = servinfo; p; p = p->ai_next)
	{
		if((s_me = socket(p->ai_family, p->ai_socktype,	p->ai_protocol)) == -1)
			continue;
		if(bind(s_me, p->ai_addr, p->ai_addrlen) == -1)
		{
			close(s_me);
			continue;
		}
		break; // created socket and bound
	}
	if(!p)
	{
		cerr << "Failed to bind socket!" << endl;
		return false;
	}
	// set socket to nonblock mode
	fcntl(s_me, F_SETFL, O_NONBLOCK);
	
	freeaddrinfo(servinfo);
	
	time_t rawtime;
	time(&rawtime);
	to_log(string("Startup on ") + ctime(&rawtime));
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
xorps %xmm0, %xmm0
movaps %xmm0, -0x20(%rbp)
movaps %xmm0, -0x30(%rbp)
movaps %xmm0, -0x40(%rbp)
leaq 0x76bcf(%rip), %rax     # 0x8fa10
movl 0x20(%rax), %eax
movl %eax, -0xd8(%rbp)
testl %eax, %eax
je 0x18e6a
jmp 0x18e50
movl -0xd8(%rbp), %eax
subl $0x4, %eax
je 0x18e73
jmp 0x18e5d
movl -0xd8(%rbp), %eax
subl $0x6, %eax
je 0x18e7c
jmp 0x18e83
movl $0x0, -0x3c(%rbp)
jmp 0x18e83
movl $0x2, -0x3c(%rbp)
jmp 0x18e83
movl $0xa, -0x3c(%rbp)
movl $0x2, -0x38(%rbp)
movl $0x1, -0x40(%rbp)
leaq 0x76b78(%rip), %rax     # 0x8fa10
movl 0x1c(%rax), %esi
leaq -0x78(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x609d0
movq -0xe8(%rbp), %rdi
callq 0x5200
movq %rax, %rsi
xorl %eax, %eax
movl %eax, %edi
leaq -0x40(%rbp), %rdx
leaq -0x48(%rbp), %rcx
callq 0x56a0
movl %eax, -0xdc(%rbp)
jmp 0x18ed3
movl -0xdc(%rbp), %eax
movl %eax, -0x54(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x5a48
movl -0xdc(%rbp), %eax
cmpl $0x0, %eax
je 0x18f56
movq 0x740f1(%rip), %rdi     # 0x8cfe8
leaq 0x4837e(%rip), %rsi     # 0x6127c
callq 0x5510
movq %rax, -0xf0(%rbp)
movl -0x54(%rbp), %edi
callq 0x5780
movq -0xf0(%rbp), %rdi
movq %rax, %rsi
callq 0x5510
movq %rax, %rdi
movq 0x7407d(%rip), %rsi     # 0x8cfa8
callq 0x5560
movb $0x0, -0x1(%rbp)
jmp 0x19108
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x5a48
jmp 0x19116
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x18fc8
movq -0x50(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x50(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x50(%rbp), %rax
movl 0xc(%rax), %edx
callq 0x5150
movl %eax, 0x76333(%rip)     # 0x8f2b8
cmpl $-0x1, %eax
jne 0x18f8c
jmp 0x18fba
movl 0x76326(%rip), %edi     # 0x8f2b8
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x50(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x50c0
cmpl $-0x1, %eax
jne 0x18fb8
movl 0x76307(%rip), %edi     # 0x8f2b8
callq 0x59e0
jmp 0x18fba
jmp 0x18fc8
movq -0x50(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x18f5e
cmpq $0x0, -0x50(%rbp)
jne 0x18ffa
movq 0x74012(%rip), %rdi     # 0x8cfe8
leaq 0x482b6(%rip), %rsi     # 0x61293
callq 0x5510
movq %rax, %rdi
movq 0x73fbc(%rip), %rsi     # 0x8cfa8
callq 0x5560
movb $0x0, -0x1(%rbp)
jmp 0x19108
movl 0x762b8(%rip), %edi     # 0x8f2b8
xorl %eax, %eax
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
callq 0x52b0
movq -0x48(%rbp), %rdi
callq 0x5710
leaq -0x90(%rbp), %rdi
callq 0x54c0
leaq -0xd1(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x5930
movq -0xf8(%rbp), %rdx
leaq 0x48263(%rip), %rsi     # 0x612aa
leaq -0xd0(%rbp), %rdi
callq 0x18880
jmp 0x19055
leaq -0x90(%rbp), %rdi
callq 0x51e0
movq %rax, %rdx
leaq -0xb0(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x18a40
jmp 0x19079
leaq -0xb0(%rbp), %rdi
callq 0x28d70
jmp 0x19087
leaq -0xb0(%rbp), %rdi
callq 0x5a48
leaq -0xd0(%rbp), %rdi
callq 0x5a48
leaq -0xd1(%rbp), %rdi
callq 0x5590
movb $0x1, -0x1(%rbp)
jmp 0x19108
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x190fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x190ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x5a48
leaq -0xd0(%rbp), %rdi
callq 0x5a48
leaq -0xd1(%rbp), %rdi
callq 0x5590
jmp 0x19116
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x80(%rbp), %rdi
callq 0x5920
nop