* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <getopt.h>
+#include <signal.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
};
bool debug = false;
+bool want_shutdown = false;
+
+void shutdown_request(int signal)
+{
+ want_shutdown = true;
+}
bool mac_compare(uint8_t *a, uint8_t *b)
{
hdr = (struct nlmsghdr *) buf;
nd = (struct ndmsg *) (hdr + 1);
- while (1) {
+ while (!want_shutdown) {
received = recv(sock, buf, sizeof(buf), 0);
if (debug) {
t = time(NULL);
nd->ndm_type);
}
attr = (struct nlattr *) (nd + 1);
- while (attr->nla_len > 0) {
- data = (((uint8_t *) attr) + 4);
+ while (((uint8_t *) attr - buf) < hdr->nlmsg_len) {
+ data = (((uint8_t *) attr) + NLA_HDRLEN);
if (attr->nla_type == NDA_LLADDR &&
nd->ndm_state == NUD_REACHABLE) {
mqtt_mac_presence(config, mosq,
data, true);
}
- attr = (struct nlattr *)
- (((uint8_t *) attr) + attr->nla_len);
+ attr = (struct nlattr *) (((uint8_t *) attr) +
+ NLA_ALIGN(attr->nla_len));
}
break;
case RTM_DELNEIGH:
case RTM_GETNEIGH:
+ break;
default:
printf("Unknown message type: %d\n", hdr->nlmsg_type);
}
if (!config.location)
config.mqtt_host = LOCATION;
+ signal(SIGTERM, shutdown_request);
+
sock = netlink_init();
mosq = mqtt_init(&config);
main_loop(&config, mosq, sock);
+
+ mosquitto_disconnect(mosq);
+ mosquitto_loop_stop(mosq, true);
+ mosquitto_destroy(mosq);
+ mosquitto_lib_cleanup();
+ close(sock);
}