// File: /workspace/github_c_makefile_star2_O0/jech[P]shncpd/ra.c
// Function: recv_rs
static int
recv_rs()
{
    int buflen = 1500, rc;
    unsigned char buf[buflen];
    struct sockaddr_in6 from;
    struct interface *interface;
    struct iovec iov[1];
    struct msghdr msg;
    int cmsglen = 100;
    char cmsgbuf[100];
    struct cmsghdr *cmsg = (struct cmsghdr*)cmsgbuf;
    int hoplimit = -1;

    iov[0].iov_base = buf;
    iov[0].iov_len = buflen;
    memset(&msg, 0, sizeof(msg));
    msg.msg_name = &from;
    msg.msg_namelen = sizeof(from);
    msg.msg_iov = iov;
    msg.msg_iovlen = 1;
    msg.msg_control = cmsg;
    msg.msg_controllen = cmsglen;

    rc = recvmsg(ra_socket, &msg, 0);
    if(rc < 0)
        return rc;

    if(msg.msg_namelen < sizeof(struct sockaddr_in6) ||
       from.sin6_family != AF_INET6)
        return 0;

    cmsg = CMSG_FIRSTHDR(&msg);
    while(cmsg != NULL) {
        if ((cmsg->cmsg_level == IPPROTO_IPV6) &&
            (cmsg->cmsg_type == IPV6_HOPLIMIT)) {
            hoplimit = *(unsigned char*)CMSG_DATA(cmsg);
            break;
        }
    }

    if(hoplimit != 255)
        return 0;

    if(rc < 8)
        return 0;

    if(buf[0] != 133 || buf[1] != 0)
        return 0;

    if(from.sin6_scope_id == 0)
        return 0;

    interface = find_interface(from.sin6_scope_id);
    if(interface == NULL)
        return 0;

    debugf("  Router Solicitation on %s\n", interface->ifname);
    schedule_ra(interface, 1, 0);

    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movl $0x5dc, -0x8(%rbp)      # imm = 0x5DC
movl -0x8(%rbp), %eax
movl %eax, %ecx
movq %rsp, %rax
movq %rax, -0x18(%rbp)
movq %rcx, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rax
subq %rdx, %rax
movq %rax, -0x118(%rbp)
movq %rax, %rsp
movq %rcx, -0x20(%rbp)
movl $0x64, -0x9c(%rbp)
leaq -0x100(%rbp), %rcx
movq %rcx, -0x108(%rbp)
movl $0xffffffff, -0x10c(%rbp) # imm = 0xFFFFFFFF
movq %rax, -0x60(%rbp)
movslq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x98(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x2170
leaq -0x3c(%rbp), %rax
movq %rax, -0x98(%rbp)
movl $0x1c, -0x90(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0x88(%rbp)
movq $0x1, -0x80(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0x78(%rbp)
movslq -0x9c(%rbp), %rax
movq %rax, -0x70(%rbp)
movl 0xc98a(%rip), %edi      # 0x161fc
leaq -0x98(%rbp), %rsi
xorl %edx, %edx
callq 0x22a0
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jge 0x989e
movl -0xc(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x110(%rbp)
jmp 0x9a30
movl -0x90(%rbp), %eax
cmpq $0x1c, %rax
jb 0x98b3
movzwl -0x3c(%rbp), %eax
cmpl $0xa, %eax
je 0x98c9
movl $0x0, -0x4(%rbp)
movl $0x1, -0x110(%rbp)
jmp 0x9a30
cmpq $0x10, -0x70(%rbp)
jb 0x98dd
movq -0x78(%rbp), %rax
movq %rax, -0x120(%rbp)
jmp 0x98e8
xorl %eax, %eax
movq %rax, -0x120(%rbp)
jmp 0x98e8
movq -0x120(%rbp), %rax
movq %rax, -0x108(%rbp)
cmpq $0x0, -0x108(%rbp)
je 0x992f
movq -0x108(%rbp), %rax
cmpl $0x29, 0x8(%rax)
jne 0x992d
movq -0x108(%rbp), %rax
cmpl $0x34, 0xc(%rax)
jne 0x992d
movq -0x108(%rbp), %rax
movzbl 0x10(%rax), %eax
movl %eax, -0x10c(%rbp)
jmp 0x992f
jmp 0x98f6
cmpl $0xff, -0x10c(%rbp)
je 0x9951
movl $0x0, -0x4(%rbp)
movl $0x1, -0x110(%rbp)
jmp 0x9a30
cmpl $0x8, -0xc(%rbp)
jge 0x996d
movl $0x0, -0x4(%rbp)
movl $0x1, -0x110(%rbp)
jmp 0x9a30
movq -0x118(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x85, %eax
jne 0x998e
movq -0x118(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x0, %eax
je 0x99a4
movl $0x0, -0x4(%rbp)
movl $0x1, -0x110(%rbp)
jmp 0x9a30
cmpl $0x0, -0x24(%rbp)
jne 0x99bd
movl $0x0, -0x4(%rbp)
movl $0x1, -0x110(%rbp)
jmp 0x9a30
movl -0x24(%rbp), %edi
callq 0x4470
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x99e3
movl $0x0, -0x4(%rbp)
movl $0x1, -0x110(%rbp)
jmp 0x9a30
jmp 0x99e5
leaq 0xc87c(%rip), %rax      # 0x16268
cmpl $0x2, (%rax)
jl 0x9a0b
movq -0x48(%rbp), %rax
movq (%rax), %rdx
movl $0x2, %edi
leaq 0x9426(%rip), %rsi      # 0x12e2a
movb $0x0, %al
callq 0xfda0
jmp 0x9a0d
jmp 0x9a0f
movq -0x48(%rbp), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x8b60
movl $0x1, -0x4(%rbp)
movl $0x1, -0x110(%rbp)
movq -0x18(%rbp), %rax
movq %rax, %rsp
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
nop