// File: /workspace/github_c_makefile_star2_O0/open-mesh-mirror[P]batmand/posix/init.c
// Function: activate_interface
static void activate_interface(struct batman_if *batman_if)
{
	struct ifreq int_req;
	int on = 1, sock_opts;

	if ( ( batman_if->udp_recv_sock = socket( PF_INET, SOCK_DGRAM, 0 ) ) < 0 ) {

		debug_output(3, "Error - can't create receive socket: %s\n", strerror(errno) );
		goto error;

	}

	memset( &int_req, 0, sizeof (struct ifreq) );
	strncpy( int_req.ifr_name, batman_if->dev, IFNAMSIZ - 1 );

	if ( ioctl( batman_if->udp_recv_sock, SIOCGIFADDR, &int_req ) < 0 ) {

		debug_output(3, "Error - can't get IP address of interface %s: %s\n", batman_if->dev, strerror(errno) );
		goto error;

	}

	batman_if->addr.sin_family = AF_INET;
	batman_if->addr.sin_port = htons(PORT);
	batman_if->addr.sin_addr.s_addr = ((struct sockaddr_in *)&int_req.ifr_addr)->sin_addr.s_addr;

	if (batman_if->addr.sin_addr.s_addr == 0) {

		debug_output(3, "Error - invalid ip address detected (0.0.0.0): %s\n", batman_if->dev);
		goto error;

	}

	if ( ioctl( batman_if->udp_recv_sock, SIOCGIFBRDADDR, &int_req ) < 0 ) {

		debug_output(3, "Error - can't get broadcast IP address of interface %s: %s\n", batman_if->dev, strerror(errno) );
		goto error;

	}

	batman_if->broad.sin_family = AF_INET;
	batman_if->broad.sin_port = htons(PORT);
	batman_if->broad.sin_addr.s_addr = ((struct sockaddr_in *)&int_req.ifr_broadaddr)->sin_addr.s_addr;

	if ( batman_if->broad.sin_addr.s_addr == 0 ) {

		debug_output(3, "Error - invalid broadcast address detected (0.0.0.0): %s\n", batman_if->dev );
		goto error;

	}


#ifdef __linux__
	/* The SIOCGIFINDEX ioctl is Linux specific, but I am not yet sure if the
	* equivalent exists on *BSD. There is a function called if_nametoindex()
	* on both Linux and BSD.
	* Maybe it does the same as this code and we can simply call it instead?
	* --stsp
	*/
	if ( ioctl( batman_if->udp_recv_sock, SIOCGIFINDEX, &int_req ) < 0 ) {

		debug_output(3, "Error - can't get index of interface %s: %s\n", batman_if->dev, strerror(errno) );
		goto error;

	}

	batman_if->if_index = int_req.ifr_ifindex;
#else
	batman_if->if_index = 0;
#endif
	batman_if->wifi_if = is_wifi_interface(batman_if->dev, batman_if->udp_recv_sock);

	if (ioctl(batman_if->udp_recv_sock, SIOCGIFNETMASK, &int_req) < 0) {

		debug_output(3, "Error - can't get netmask address of interface %s: %s\n", batman_if->dev, strerror(errno));
		goto error;

	}

	batman_if->netaddr = (((struct sockaddr_in *)&int_req.ifr_addr)->sin_addr.s_addr & batman_if->addr.sin_addr.s_addr);
	batman_if->netmask = bit_count(((struct sockaddr_in *)&int_req.ifr_addr)->sin_addr.s_addr);

	add_del_rule(batman_if->netaddr, batman_if->netmask, BATMAN_RT_TABLE_HOSTS, BATMAN_RT_PRIO_DEFAULT + batman_if->if_num, 0, RULE_TYPE_DST, RULE_ADD);
	add_del_rule(batman_if->netaddr, batman_if->netmask, BATMAN_RT_TABLE_UNREACH, BATMAN_RT_PRIO_UNREACH + batman_if->if_num, 0, RULE_TYPE_DST, RULE_ADD);

	if ( ( batman_if->udp_send_sock = socket( PF_INET, SOCK_DGRAM, 0 ) ) < 0 ) {

		debug_output(3, "Error - can't create send socket: %s\n", strerror(errno) );
		goto error;

	}

	if ( setsockopt( batman_if->udp_send_sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on) ) < 0 ) {

		debug_output(3, "Error - can't enable broadcasts: %s\n", strerror(errno) );
		goto error;

	}

	if ( bind_to_iface( batman_if->udp_send_sock, batman_if->dev ) < 0 ) {

		debug_output(3, "Cannot bind socket to device %s : %s \n", batman_if->dev, strerror(errno));
		goto error;

	}

	if ( bind( batman_if->udp_send_sock, (struct sockaddr *)&batman_if->addr, sizeof(struct sockaddr_in) ) < 0 ) {

		debug_output(3, "Error - can't bind send socket: %s\n", strerror(errno) );
		goto error;

	}

	/* make udp socket non blocking */
	sock_opts = fcntl(batman_if->udp_send_sock, F_GETFL, 0);
	fcntl(batman_if->udp_send_sock, F_SETFL, sock_opts | O_NONBLOCK);

	if ( bind_to_iface( batman_if->udp_recv_sock, batman_if->dev ) < 0 ) {

		debug_output(3, "Cannot bind socket to device %s : %s \n", batman_if->dev, strerror(errno));
		goto error;

	}

	if ( bind( batman_if->udp_recv_sock, (struct sockaddr *)&batman_if->broad, sizeof(struct sockaddr_in) ) < 0 ) {

		debug_output(3, "Error - can't bind receive socket: %s\n", strerror(errno));
		goto error;

	}

	batman_if->out.orig = batman_if->addr.sin_addr.s_addr;
	batman_if->out.prev_sender = batman_if->addr.sin_addr.s_addr;

	batman_if->if_active = 1;
	active_ifs++;

	interface_listen_sockets();
	debug_output(3, "Interface activated: %s\n", batman_if->dev);

	batman_if->if_rp_filter_old = get_rp_filter(batman_if->dev);
	set_rp_filter(0, batman_if->dev);

	batman_if->if_send_redirects_old = get_send_redirects(batman_if->dev);
	set_send_redirects(0, batman_if->dev);

	return;

error:
	deactivate_interface(batman_if);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl $0x1, -0x34(%rbp)
movl $0x2, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x2500
movq -0x8(%rbp), %rcx
movl %eax, 0x14(%rcx)
cmpl $0x0, %eax
jge 0xebc7
callq 0x2070
movl (%rax), %edi
callq 0x24a0
movq %rax, %rdx
movl $0x3, %edi
leaq 0x8594(%rip), %rsi      # 0x1714f
movb $0x0, %al
callq 0x123f0
jmp 0xf148
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x21e0
leaq -0x30(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
movl $0xf, %edx
callq 0x2090
movq -0x8(%rbp), %rax
movl 0x14(%rax), %edi
movl $0x8915, %esi           # imm = 0x8915
leaq -0x30(%rbp), %rdx
movb $0x0, %al
callq 0x21f0
cmpl $0x0, %eax
jge 0xec40
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
callq 0x2070
movl (%rax), %edi
callq 0x24a0
movq -0x50(%rbp), %rdx
movq %rax, %rcx
movl $0x3, %edi
leaq 0x8544(%rip), %rsi      # 0x17178
movb $0x0, %al
callq 0x123f0
jmp 0xf148
movq -0x8(%rbp), %rax
movw $0x2, 0x30(%rax)
movl $0x10d1, %edi           # imm = 0x10D1
callq 0x2170
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x32(%rax)
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x34(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x34(%rax)
jne 0xec93
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x3, %edi
leaq 0x8523(%rip), %rsi      # 0x171aa
movb $0x0, %al
callq 0x123f0
jmp 0xf148
movq -0x8(%rbp), %rax
movl 0x14(%rax), %edi
movl $0x8919, %esi           # imm = 0x8919
leaq -0x30(%rbp), %rdx
movb $0x0, %al
callq 0x21f0
cmpl $0x0, %eax
jge 0xece6
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
callq 0x2070
movl (%rax), %edi
callq 0x24a0
movq -0x58(%rbp), %rdx
movq %rax, %rcx
movl $0x3, %edi
leaq 0x8503(%rip), %rsi      # 0x171dd
movb $0x0, %al
callq 0x123f0
jmp 0xf148
movq -0x8(%rbp), %rax
movw $0x2, 0x40(%rax)
movl $0x10d1, %edi           # imm = 0x10D1
callq 0x2170
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x42(%rax)
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x44(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x44(%rax)
jne 0xed39
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x3, %edi
leaq 0x84ec(%rip), %rsi      # 0x17219
movb $0x0, %al
callq 0x123f0
jmp 0xf148
movq -0x8(%rbp), %rax
movl 0x14(%rax), %edi
movl $0x8933, %esi           # imm = 0x8933
leaq -0x30(%rbp), %rdx
movb $0x0, %al
callq 0x21f0
cmpl $0x0, %eax
jge 0xed8c
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
callq 0x2070
movl (%rax), %edi
callq 0x24a0
movq -0x60(%rbp), %rdx
movq %rax, %rcx
movl $0x3, %edi
leaq 0x84d3(%rip), %rsi      # 0x17253
movb $0x0, %al
callq 0x123f0
jmp 0xf148
movl -0x20(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x14(%rax), %esi
callq 0xcb00
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x55(%rax)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %edi
movl $0x891b, %esi           # imm = 0x891B
leaq -0x30(%rbp), %rdx
movb $0x0, %al
callq 0x21f0
cmpl $0x0, %eax
jge 0xee06
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
callq 0x2070
movl (%rax), %edi
callq 0x24a0
movq -0x68(%rbp), %rdx
movq %rax, %rcx
movl $0x3, %edi
leaq 0x8486(%rip), %rsi      # 0x17280
movb $0x0, %al
callq 0x123f0
jmp 0xf148
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
andl 0x34(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x50(%rax)
movl -0x1c(%rbp), %edi
callq 0x7e30
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x54(%rax)
movq -0x8(%rbp), %rax
movl 0x50(%rax), %edi
movq -0x8(%rbp), %rax
movb 0x54(%rax), %al
movq -0x8(%rbp), %rcx
movzbl 0x1c(%rcx), %ecx
addl $0x19c8, %ecx           # imm = 0x19C8
movl $0x42, %edx
xorl %esi, %esi
movl %esi, %r8d
movl $0x1, %r9d
xorl %esi, %esi
movzbl %al, %esi
movl $0x0, (%rsp)
callq 0xacd0
movq -0x8(%rbp), %rax
movl 0x50(%rax), %edi
movq -0x8(%rbp), %rax
movb 0x54(%rax), %al
movq -0x8(%rbp), %rcx
movzbl 0x1c(%rcx), %ecx
addl $0x1a2c, %ecx           # imm = 0x1A2C
movl $0x43, %edx
xorl %esi, %esi
movl %esi, %r8d
movl $0x1, %r9d
xorl %esi, %esi
movzbl %al, %esi
movl $0x0, (%rsp)
callq 0xacd0
movl $0x2, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x2500
movq -0x8(%rbp), %rcx
movl %eax, 0x10(%rcx)
cmpl $0x0, %eax
jge 0xeee3
callq 0x2070
movl (%rax), %edi
callq 0x24a0
movq %rax, %rdx
movl $0x3, %edi
leaq 0x83e0(%rip), %rsi      # 0x172b7
movb $0x0, %al
callq 0x123f0
jmp 0xf148
movq -0x8(%rbp), %rax
movl 0x10(%rax), %edi
movl $0x1, %esi
movl $0x6, %edx
leaq -0x34(%rbp), %rcx
movl $0x4, %r8d
callq 0x20d0
cmpl $0x0, %eax
jge 0xef2f
callq 0x2070
movl (%rax), %edi
callq 0x24a0
movq %rax, %rdx
movl $0x3, %edi
leaq 0x83ba(%rip), %rsi      # 0x172dd
movb $0x0, %al
callq 0x123f0
jmp 0xf148
movq -0x8(%rbp), %rax
movl 0x10(%rax), %edi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0xca60
movsbl %al, %eax
cmpl $0x0, %eax
jge 0xef82
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
callq 0x2070
movl (%rax), %edi
callq 0x24a0
movq -0x70(%rbp), %rdx
movq %rax, %rcx
movl $0x3, %edi
leaq 0x838c(%rip), %rsi      # 0x17302
movb $0x0, %al
callq 0x123f0
jmp 0xf148
movq -0x8(%rbp), %rax
movl 0x10(%rax), %edi
movq -0x8(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rsi
movl $0x10, %edx
callq 0x23a0
cmpl $0x0, %eax
jge 0xefcf
callq 0x2070
movl (%rax), %edi
callq 0x24a0
movq %rax, %rdx
movl $0x3, %edi
leaq 0x8366(%rip), %rsi      # 0x17329
movb $0x0, %al
callq 0x123f0
jmp 0xf148
movq -0x8(%rbp), %rax
movl 0x10(%rax), %edi
movl $0x3, %esi
xorl %edx, %edx
movb $0x0, %al
callq 0x20e0
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %edi
movl -0x38(%rbp), %edx
orl $0x800, %edx            # imm = 0x800
movl $0x4, %esi
movb $0x0, %al
callq 0x20e0
movq -0x8(%rbp), %rax
movl 0x14(%rax), %edi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0xca60
movsbl %al, %eax
cmpl $0x0, %eax
jge 0xf056
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x78(%rbp)
callq 0x2070
movl (%rax), %edi
callq 0x24a0
movq -0x78(%rbp), %rdx
movq %rax, %rcx
movl $0x3, %edi
leaq 0x82b8(%rip), %rsi      # 0x17302
movb $0x0, %al
callq 0x123f0
jmp 0xf148
movq -0x8(%rbp), %rax
movl 0x14(%rax), %edi
movq -0x8(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rsi
movl $0x10, %edx
callq 0x23a0
cmpl $0x0, %eax
jge 0xf0a3
callq 0x2070
movl (%rax), %edi
callq 0x24a0
movq %rax, %rdx
movl $0x3, %edi
leaq 0x82b6(%rip), %rsi      # 0x1734d
movb $0x0, %al
callq 0x123f0
jmp 0xf148
movq -0x8(%rbp), %rax
movl 0x34(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x5e(%rax)
movq -0x8(%rbp), %rax
movl 0x34(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x62(%rax)
movq -0x8(%rbp), %rax
movb $0x1, 0x1d(%rax)
leaq 0xc2b7(%rip), %rax      # 0x1b385
movb (%rax), %cl
addb $0x1, %cl
leaq 0xc2ab(%rip), %rax      # 0x1b385
movb %cl, (%rax)
callq 0xe830
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x3, %edi
leaq 0x827f(%rip), %rsi      # 0x17374
movb $0x0, %al
callq 0x123f0
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xc820
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x24(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
xorl %edi, %edi
callq 0xc750
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xc9a0
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x25(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
xorl %edi, %edi
callq 0xc920
jmp 0xf151
movq -0x8(%rbp), %rdi
callq 0xe930
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)