// File: /workspace/github_c_makefile_star2_O0/jech[P]shncpd/ra.c
// Function: setup_ra_socket
int
setup_ra_socket()
{
    int s, i, rc, one = 1, ff = 255;
    struct icmp6_filter filter;

    if(ra_socket >= 0) {
        close(ra_socket);
        ra_socket = -1;
    }

    s = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
    if(s < 0)
        return -1;

    rc = setsockopt(s, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ff, sizeof(ff));
    if(rc < 0)
        goto fail;

    rc = setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &ff, sizeof(ff));
    if(rc < 0)
        goto fail;

    rc = setsockopt(s, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &one, sizeof(one));
    if(rc < 0)
        goto fail;

    for(i = 0; i < numinterfaces; i++) {
        struct ipv6_mreq mreq;
        const unsigned char all_routers[16] =
            {0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02};
        if(interfaces[i].ifindex <= 0)
            continue;
        memset(&mreq, 0, sizeof(mreq));
        memcpy(&mreq.ipv6mr_multiaddr, &all_routers, 16);
        mreq.ipv6mr_interface = interfaces[i].ifindex;
        rc = setsockopt(s, IPPROTO_IPV6, IPV6_JOIN_GROUP,
                        (char*)&mreq, sizeof(mreq));
        if(rc < 0)
            goto fail;
    }

    ICMP6_FILTER_SETBLOCKALL(&filter);
    ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT, &filter);

    rc = setsockopt(s, IPPROTO_ICMPV6, ICMP6_FILTER, &filter, sizeof(filter));
    if(rc < 0)
        goto fail;

    rc = fcntl(s, F_GETFD, 0);
    if(rc < 0)
        goto fail;

    rc = fcntl(s, F_SETFD, rc | FD_CLOEXEC);
    if(rc < 0)
        goto fail;

    rc = fcntl(s, F_GETFL, 0);
    if(rc < 0)
        goto fail;

    rc = fcntl(s, F_SETFL, (rc | O_NONBLOCK));
    if(rc < 0)
        goto fail;

    ra_socket = s;
    return s;

fail:
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl $0x1, -0x14(%rbp)
movl $0xff, -0x18(%rbp)
cmpl $0x0, 0xd9af(%rip)      # 0x161fc
jl 0x8864
movl 0xd9a7(%rip), %edi      # 0x161fc
callq 0x21a0
movl $0xffffffff, 0xd998(%rip) # imm = 0xFFFFFFFF
movl $0xa, %edi
movl $0x3, %esi
movl $0x3a, %edx
callq 0x23b0
movl %eax, -0x8(%rbp)
cmpl $0x0, -0x8(%rbp)
jge 0x888d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8aa3
movl -0x8(%rbp), %edi
movl $0x29, %esi
movl $0x10, %edx
leaq -0x18(%rbp), %rcx
movl $0x4, %r8d
callq 0x2090
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jge 0x88b7
jmp 0x8a9c
movl -0x8(%rbp), %edi
movl $0x29, %esi
movl $0x12, %edx
leaq -0x18(%rbp), %rcx
movl $0x4, %r8d
callq 0x2090
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jge 0x88e1
jmp 0x8a9c
movl -0x8(%rbp), %edi
movl $0x29, %esi
movl $0x33, %edx
leaq -0x14(%rbp), %rcx
movl $0x4, %r8d
callq 0x2090
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jge 0x890b
jmp 0x8a9c
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
leaq 0xd994(%rip), %rcx      # 0x162b0
cmpl (%rcx), %eax
jge 0x89ca
movq 0xa495(%rip), %rax      # 0x12dc0
movq %rax, -0x60(%rbp)
movq 0xa492(%rip), %rax      # 0x12dc8
movq %rax, -0x58(%rbp)
movslq -0xc(%rbp), %rcx
leaq 0xd97b(%rip), %rax      # 0x162c0
imulq $0x98, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x8(%rax)
jg 0x8957
jmp 0x89bc
leaq -0x4c(%rbp), %rdi
xorl %esi, %esi
movl $0x14, %edx
callq 0x2170
movq -0x60(%rbp), %rax
movq %rax, -0x4c(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x44(%rbp)
movslq -0xc(%rbp), %rcx
leaq 0xd93e(%rip), %rax      # 0x162c0
imulq $0x98, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x3c(%rbp)
movl -0x8(%rbp), %edi
movl $0x29, %esi
movl $0x14, %r8d
leaq -0x4c(%rbp), %rcx
movl %r8d, %edx
callq 0x2090
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jge 0x89ba
jmp 0x8a9c
jmp 0x89bc
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x8912
leaq -0x38(%rbp), %rdi
movl $0xff, %esi
movl $0x20, %edx
callq 0x2170
movl -0x28(%rbp), %eax
andl $-0x21, %eax
movl %eax, -0x28(%rbp)
movl -0x8(%rbp), %edi
movl $0x3a, %esi
movl $0x1, %edx
leaq -0x38(%rbp), %rcx
movl $0x20, %r8d
callq 0x2090
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jge 0x8a10
jmp 0x8a9c
movl -0x8(%rbp), %edi
movl $0x1, %esi
xorl %edx, %edx
movb $0x0, %al
callq 0x20a0
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jge 0x8a2c
jmp 0x8a9c
movl -0x8(%rbp), %edi
movl -0x10(%rbp), %edx
orl $0x1, %edx
movl $0x2, %esi
movb $0x0, %al
callq 0x20a0
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jge 0x8a4c
jmp 0x8a9c
movl -0x8(%rbp), %edi
movl $0x3, %esi
xorl %edx, %edx
movb $0x0, %al
callq 0x20a0
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jge 0x8a68
jmp 0x8a9c
movl -0x8(%rbp), %edi
movl -0x10(%rbp), %edx
orl $0x800, %edx            # imm = 0x800
movl $0x4, %esi
movb $0x0, %al
callq 0x20a0
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jge 0x8a8b
jmp 0x8a9c
movl -0x8(%rbp), %eax
movl %eax, 0xd768(%rip)      # 0x161fc
movl -0x8(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8aa3
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)