socket: add debug callbacks for rx/tx
[project/libnl-tiny.git] / nl.c
diff --git a/nl.c b/nl.c
index 32d26a3f763525f525b66e4e6a5b7923935a3051..fee0529b3a73430994ba74624b94b707af5b9f4d 100644 (file)
--- a/nl.c
+++ b/nl.c
@@ -192,6 +192,9 @@ int nl_sendto(struct nl_sock *sk, void *buf, size_t size)
 {
        int ret;
 
+       if (sk->s_debug_tx_cb)
+               sk->s_debug_tx_cb(sk->s_debug_tx_priv, buf, size);
+
        ret = sendto(sk->s_fd, buf, size, 0, (struct sockaddr *)
                     &sk->s_peer, sizeof(sk->s_peer));
        if (ret < 0)
@@ -227,6 +230,9 @@ int nl_sendmsg(struct nl_sock *sk, struct nl_msg *msg, struct msghdr *hdr)
                if (nl_cb_call(cb, NL_CB_MSG_OUT, msg) != NL_OK)
                        return 0;
 
+       if (sk->s_debug_tx_cb)
+               sk->s_debug_tx_cb(sk->s_debug_tx_priv, iov.iov_base, iov.iov_len);
+
        ret = sendmsg(sk->s_fd, hdr, 0);
        if (ret < 0)
                return -nl_syserr2nlerr(errno);
@@ -466,6 +472,9 @@ retry:
                }
        }
 
+       if (sk->s_debug_rx_cb)
+               sk->s_debug_rx_cb(sk->s_debug_rx_priv, *buf, n);
+
        free(msg.msg_control);
        return n;