xref: /freebsd-12.1/share/dtrace/udptrack (revision 8a502e74)
11dfaa6f1SGeorge V. Neville-Neil#!/usr/sbin/dtrace -s
21dfaa6f1SGeorge V. Neville-Neil/*
31dfaa6f1SGeorge V. Neville-Neil * Copyright (c) 2015 George V. Neville-Neil
41dfaa6f1SGeorge V. Neville-Neil * All rights reserved.
51dfaa6f1SGeorge V. Neville-Neil *
61dfaa6f1SGeorge V. Neville-Neil * Redistribution and use in source and binary forms, with or without
71dfaa6f1SGeorge V. Neville-Neil * modification, are permitted provided that the following conditions
81dfaa6f1SGeorge V. Neville-Neil * are met:
91dfaa6f1SGeorge V. Neville-Neil * 1. Redistributions of source code must retain the above copyright
101dfaa6f1SGeorge V. Neville-Neil *    notice, this list of conditions and the following disclaimer.
111dfaa6f1SGeorge V. Neville-Neil * 2. Redistributions in binary form must reproduce the above copyright
121dfaa6f1SGeorge V. Neville-Neil *    notice, this list of conditions and the following disclaimer in the
131dfaa6f1SGeorge V. Neville-Neil *    documentation and/or other materials provided with the distribution.
141dfaa6f1SGeorge V. Neville-Neil *
151dfaa6f1SGeorge V. Neville-Neil * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
161dfaa6f1SGeorge V. Neville-Neil * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
171dfaa6f1SGeorge V. Neville-Neil * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
181dfaa6f1SGeorge V. Neville-Neil * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
191dfaa6f1SGeorge V. Neville-Neil * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
201dfaa6f1SGeorge V. Neville-Neil * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
211dfaa6f1SGeorge V. Neville-Neil * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
221dfaa6f1SGeorge V. Neville-Neil * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
231dfaa6f1SGeorge V. Neville-Neil * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
241dfaa6f1SGeorge V. Neville-Neil * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
251dfaa6f1SGeorge V. Neville-Neil * SUCH DAMAGE.
261dfaa6f1SGeorge V. Neville-Neil *
271dfaa6f1SGeorge V. Neville-Neil * $FreeBSD$
281dfaa6f1SGeorge V. Neville-Neil *
291dfaa6f1SGeorge V. Neville-Neil * The udptrack D script shows various information about UDP
301dfaa6f1SGeorge V. Neville-Neil * data that are sent and received on the host.
311dfaa6f1SGeorge V. Neville-Neil *
321dfaa6f1SGeorge V. Neville-Neil * Usage: udptrack
331dfaa6f1SGeorge V. Neville-Neil */
341dfaa6f1SGeorge V. Neville-Neil
351dfaa6f1SGeorge V. Neville-Neil#pragma D option quiet
361dfaa6f1SGeorge V. Neville-Neiludp:kernel::receive
371dfaa6f1SGeorge V. Neville-Neil{
381dfaa6f1SGeorge V. Neville-Neil	printf("Received %d bytes of data from %s:%d\n",
391dfaa6f1SGeorge V. Neville-Neil	       args[4]->udp_length,
40*8a502e74SGeorge V. Neville-Neil	       args[2]->ip_saddr,
41*8a502e74SGeorge V. Neville-Neil	       args[4]->udp_sport);
421dfaa6f1SGeorge V. Neville-Neil	tracemem(args[4]->udp_hdr, 64);
431dfaa6f1SGeorge V. Neville-Neil}
441dfaa6f1SGeorge V. Neville-Neil
451dfaa6f1SGeorge V. Neville-Neiludp:kernel::send
461dfaa6f1SGeorge V. Neville-Neil{
471dfaa6f1SGeorge V. Neville-Neil	printf("Sent %d bytes of data to %s:%d\n",
481dfaa6f1SGeorge V. Neville-Neil	       args[4]->udp_length,
491dfaa6f1SGeorge V. Neville-Neil	       args[2]->ip_daddr,
50*8a502e74SGeorge V. Neville-Neil	       args[4]->udp_dport);
511dfaa6f1SGeorge V. Neville-Neil	tracemem(args[4]->udp_hdr, 64);
521dfaa6f1SGeorge V. Neville-Neil}
531dfaa6f1SGeorge V. Neville-Neil
54