- // Get LL-addr
- FILE *fp = fopen("/proc/net/if_inet6", "r");
- if (fp) {
- char addrbuf[33], ifbuf[16];
- while (fscanf(fp, "%32s %*x %*x %*x %*x %15s", addrbuf, ifbuf) == 2) {
- if (!strcmp(ifbuf, if_name)) {
- script_unhexlify((uint8_t*)&lladdr, sizeof(lladdr), addrbuf);
- break;
- }
- }
- fclose(fp);
- }
-
- // Open rtnetlink socket
- rtnl_sock = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE);
- struct sockaddr_nl rtnl_kernel = { .nl_family = AF_NETLINK };
- if (connect(rtnl_sock, (struct sockaddr*)&rtnl_kernel, sizeof(rtnl_kernel)))
- return -1;
- uint32_t group = RTNLGRP_IPV6_IFADDR;
- setsockopt(rtnl_sock, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &group, sizeof(group));
-
- // Add async-mode
- fcntl(rtnl_sock, F_SETOWN, ourpid);
- fcntl(rtnl_sock, F_SETFL, fcntl(rtnl_sock, F_GETFL) | O_ASYNC);
-