aboutsummaryrefslogtreecommitdiffstats
path: root/extcap/dpauxmon.c
diff options
context:
space:
mode:
Diffstat (limited to 'extcap/dpauxmon.c')
-rw-r--r--extcap/dpauxmon.c60
1 files changed, 31 insertions, 29 deletions
diff --git a/extcap/dpauxmon.c b/extcap/dpauxmon.c
index 0ab4f576cc..f3bed612d9 100644
--- a/extcap/dpauxmon.c
+++ b/extcap/dpauxmon.c
@@ -11,6 +11,7 @@
*/
#include "config.h"
+#define WS_LOG_DOMAIN "dpauxmon"
#include "extcap-base.h"
@@ -18,6 +19,7 @@
#include <wsutil/filesystem.h>
#include <wsutil/netlink.h>
#include <wsutil/privileges.h>
+#include <wsutil/wslog.h>
#include <writecap/pcapio.h>
#include <netlink/netlink.h>
@@ -75,12 +77,12 @@ static int list_config(char *interface)
unsigned inc = 0;
if (!interface) {
- g_warning("No interface specified.");
+ ws_warning("No interface specified.");
return EXIT_FAILURE;
}
if (g_strcmp0(interface, DPAUXMON_EXTCAP_INTERFACE)) {
- g_warning("interface must be %s", DPAUXMON_EXTCAP_INTERFACE);
+ ws_warning("interface must be %s", DPAUXMON_EXTCAP_INTERFACE);
return EXIT_FAILURE;
}
@@ -110,12 +112,12 @@ static int setup_dumpfile(const char* fifo, FILE** fp)
*fp = fopen(fifo, "wb");
if (!(*fp)) {
- g_warning("Error creating output file: %s", g_strerror(errno));
+ ws_warning("Error creating output file: %s", g_strerror(errno));
return EXIT_FAILURE;
}
if (!libpcap_write_file_header(*fp, 275, PCAP_SNAPLEN, FALSE, &bytes_written, &err)) {
- g_warning("Can't write pcap file header");
+ ws_warning("Can't write pcap file header");
return EXIT_FAILURE;
}
@@ -129,7 +131,7 @@ static int dump_packet(FILE* fp, const char* buf, const guint32 buflen, guint64
int ret = EXIT_SUCCESS;
if (!libpcap_write_packet(fp, ts_usecs / 1000000, ts_usecs % 1000000, buflen, buflen, buf, &bytes_written, &err)) {
- g_warning("Can't write packet");
+ ws_warning("Can't write packet");
ret = EXIT_FAILURE;
}
@@ -250,7 +252,7 @@ static int nl_receive_timeout(struct nl_sock* sk, struct sockaddr_nl* nla, unsig
int poll_res = poll(&fds, 1, 500);
if (poll_res < 0) {
- g_debug("poll() failed in nl_receive_timeout");
+ ws_debug("poll() failed in nl_receive_timeout");
g_usleep(500000);
return -nl_syserr2nlerr(errno);
}
@@ -267,26 +269,26 @@ static int send_start(struct nl_sock *sock, int family, unsigned int interface_i
msg = nlmsg_alloc();
if (msg == NULL) {
- g_critical("Unable to allocate netlink message");
+ ws_critical("Unable to allocate netlink message");
return -ENOMEM;
}
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, 0,
DPAUXMON_CMD_START, 1);
if (hdr == NULL) {
- g_critical("Unable to write genl header");
+ ws_critical("Unable to write genl header");
res = -ENOMEM;
goto out_free;
}
if ((err = nla_put_u32(msg, DPAUXMON_ATTR_IFINDEX, interface_id)) < 0) {
- g_critical("Unable to add attribute: %s", nl_geterror(err));
+ ws_critical("Unable to add attribute: %s", nl_geterror(err));
res = -EIO;
goto out_free;
}
if ((err = nl_send_auto_complete(sock, msg)) < 0)
- g_debug("Starting monitor failed, already running?");
+ ws_debug("Starting monitor failed, already running?");
out_free:
nlmsg_free(msg);
@@ -301,24 +303,24 @@ static void send_stop(struct nl_sock *sock, int family, unsigned int interface_i
msg = nlmsg_alloc();
if (msg == NULL) {
- g_critical("Unable to allocate netlink message");
+ ws_critical("Unable to allocate netlink message");
return;
}
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, 0,
DPAUXMON_CMD_STOP, 1);
if (hdr == NULL) {
- g_critical("Unable to write genl header");
+ ws_critical("Unable to write genl header");
goto out_free;
}
if ((err = nla_put_u32(msg, DPAUXMON_ATTR_IFINDEX, interface_id)) < 0) {
- g_critical("Unable to add attribute: %s", nl_geterror(err));
+ ws_critical("Unable to add attribute: %s", nl_geterror(err));
goto out_free;
}
if ((err = nl_send_auto_complete(sock, msg)) < 0) {
- g_critical("Unable to send message: %s", nl_geterror(err));
+ ws_critical("Unable to send message: %s", nl_geterror(err));
goto out_free;
}
@@ -341,7 +343,7 @@ static int handle_data(struct nl_cache_ops *unused _U_, struct genl_cmd *cmd _U_
data_size = nla_len(info->attrs[DPAUXMON_ATTR_DATA]);
if (data_size > 19) {
- g_debug("Invalid packet size %u", data_size);
+ ws_debug("Invalid packet size %u", data_size);
return NL_SKIP;
}
@@ -407,7 +409,7 @@ static void run_listener(const char* fifo, unsigned int interface_id)
struct nl_cb *socket_cb;
if (sigaction(SIGINT, &int_handler, 0)) {
- g_warning("Can't set signal handler");
+ ws_warning("Can't set signal handler");
return;
}
@@ -417,30 +419,30 @@ static void run_listener(const char* fifo, unsigned int interface_id)
}
if (!(sock = nl_socket_alloc())) {
- g_critical("Unable to allocate netlink socket");
+ ws_critical("Unable to allocate netlink socket");
goto close_out;
}
if ((err = nl_connect(sock, NETLINK_GENERIC)) < 0) {
- g_critical("Unable to connect netlink socket: %s",
+ ws_critical("Unable to connect netlink socket: %s",
nl_geterror(err));
goto free_out;
}
if ((err = genl_register_family(&ops)) < 0) {
- g_critical("Unable to register Generic Netlink family");
+ ws_critical("Unable to register Generic Netlink family");
goto err_out;
}
if ((err = genl_ops_resolve(sock, &ops)) < 0) {
- g_critical("Unable to resolve family name");
+ ws_critical("Unable to resolve family name");
goto err_out;
}
/* register notification handler callback */
if ((err = nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM,
parse_cb, NULL)) < 0) {
- g_critical("Unable to modify valid message callback");
+ ws_critical("Unable to modify valid message callback");
goto err_out;
}
@@ -448,7 +450,7 @@ static void run_listener(const char* fifo, unsigned int interface_id)
nl_socket_add_membership(sock, grp);
if (!(socket_cb = nl_socket_get_cb(sock))) {
- g_warning("Can't overwrite recv callback");
+ ws_warning("Can't overwrite recv callback");
} else {
nl_cb_overwrite_recv(socket_cb, nl_receive_timeout);
nl_cb_put(socket_cb);
@@ -460,11 +462,11 @@ static void run_listener(const char* fifo, unsigned int interface_id)
nl_socket_disable_seq_check(sock);
- g_debug("DisplayPort AUX monitor running on interface %u", interface_id);
+ ws_debug("DisplayPort AUX monitor running on interface %u", interface_id);
while(run_loop == TRUE) {
if ((err = nl_recvmsgs_default(sock)) < 0)
- g_warning("Unable to receive message: %s", nl_geterror(err));
+ ws_warning("Unable to receive message: %s", nl_geterror(err));
}
send_stop(sock, ops.o_id, interface_id);
@@ -498,7 +500,7 @@ int main(int argc, char *argv[])
*/
init_progfile_dir_error = init_progfile_dir(argv[0]);
if (init_progfile_dir_error != NULL) {
- g_warning("Can't get pathname of directory containing the captype program: %s.",
+ ws_warning("Can't get pathname of directory containing the captype program: %s.",
init_progfile_dir_error);
g_free(init_progfile_dir_error);
}
@@ -541,19 +543,19 @@ int main(int argc, char *argv[])
case OPT_INTERFACE_ID:
if (!ws_strtou32(optarg, NULL, &interface_id)) {
- g_warning("Invalid interface id: %s", optarg);
+ ws_warning("Invalid interface id: %s", optarg);
goto end;
}
break;
case ':':
/* missing option argument */
- g_warning("Option '%s' requires an argument", argv[optind - 1]);
+ ws_warning("Option '%s' requires an argument", argv[optind - 1]);
break;
default:
if (!extcap_base_parse_options(extcap_conf, result - EXTCAP_OPT_LIST_INTERFACES, optarg)) {
- g_warning("Invalid option: %s", argv[optind - 1]);
+ ws_warning("Invalid option: %s", argv[optind - 1]);
goto end;
}
}
@@ -562,7 +564,7 @@ int main(int argc, char *argv[])
extcap_cmdline_debug(argv, argc);
if (optind != argc) {
- g_warning("Unexpected extra option: %s", argv[optind]);
+ ws_warning("Unexpected extra option: %s", argv[optind]);
goto end;
}