* 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);
{ "host", required_argument, 0, 'h' },
{ "location", required_argument, 0, 'l' },
{ "mac", required_argument, 0, 'm' },
+ { "password", required_argument, 0, 'P' },
{ "port", required_argument, 0, 'p' },
{ "topic", required_argument, 0, 't' },
+ { "username", required_argument, 0, 'u' },
{ "verbose", no_argument, 0, 'v' },
{ 0, 0, 0, 0 }
};
config.mqtt_port = MQTT_PORT;
while (1) {
- c = getopt_long(argc, argv, "c:h:l:m:p:t:v",
+ c = getopt_long(argc, argv, "c:h:l:m:p:P:t:u:v",
long_options, &option_index);
if (c == -1)
&config.macs[macs].mac[3],
&config.macs[macs].mac[4],
&config.macs[macs].mac[5]);
+ config.macs[macs].valid = true;
+ macs++;
break;
case 'p':
config.mqtt_port = atoi(optarg);
break;
+ case 'P':
+ config.mqtt_password = optarg;
+ break;
case 't':
config.mqtt_topic = optarg;
break;
+ case 'u':
+ config.mqtt_username = optarg;
+ break;
case 'v':
debug = true;
break;
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);
}