]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - cddl/lib/libdtrace/udp.d
Merge bmake 20151020
[FreeBSD/FreeBSD.git] / cddl / lib / libdtrace / udp.d
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  *
21  * $FreeBSD$
22  */
23 /*
24  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
25  * Copyright (c) 2013 Mark Johnston <markj@FreeBSD.org>
26  */
27
28 #pragma D depends_on library ip.d
29 #pragma D depends_on module kernel
30 #pragma D depends_on provider udp
31
32 /*
33  * udpsinfo contains stable UDP details.
34  */
35 typedef struct udpsinfo {
36         uintptr_t udps_addr;
37         uint16_t udps_lport;            /* local port */
38         uint16_t udps_rport;            /* remote port */
39         string udps_laddr;              /* local address, as a string */
40         string udps_raddr;              /* remote address, as a string */
41 } udpsinfo_t;
42
43 /*
44  * udpinfo is the UDP header fields.
45  */
46 typedef struct udpinfo {
47         uint16_t udp_sport;             /* source port */
48         uint16_t udp_dport;             /* destination port */
49         uint16_t udp_length;            /* total length */
50         uint16_t udp_checksum;          /* headers + data checksum */
51         struct udphdr *udp_hdr;         /* raw UDP header */
52 } udpinfo_t;
53
54 #pragma D binding "1.6.3" translator
55 translator udpsinfo_t < struct inpcb *p > {
56         udps_addr =     (uintptr_t)p;
57         udps_lport =    p == NULL ? 0 : ntohs(p->inp_inc.inc_ie.ie_lport);
58         udps_rport =    p == NULL ? 0 : ntohs(p->inp_inc.inc_ie.ie_fport);
59         udps_laddr =    p == NULL ? "" :
60             p->inp_vflag == INP_IPV4 ?
61             inet_ntoa(&p->inp_inc.inc_ie.ie_dependladdr.ie46_local.ia46_addr4.s_addr) :
62             inet_ntoa6(&p->inp_inc.inc_ie.ie_dependladdr.ie6_local);
63         udps_raddr =    p == NULL ? "" :
64             p->inp_vflag == INP_IPV4 ?
65             inet_ntoa(&p->inp_inc.inc_ie.ie_dependfaddr.ie46_foreign.ia46_addr4.s_addr) :
66             inet_ntoa6(&p->inp_inc.inc_ie.ie_dependfaddr.ie6_foreign);
67 };
68
69 #pragma D binding "1.6.3" translator
70 translator udpinfo_t < struct udphdr *p > {
71         udp_sport =     p == NULL ? 0 : ntohs(p->uh_sport);
72         udp_dport =     p == NULL ? 0 : ntohs(p->uh_dport);
73         udp_length =    p == NULL ? 0 : ntohs(p->uh_ulen);
74         udp_checksum =  p == NULL ? 0 : ntohs(p->uh_sum);
75         udp_hdr =       p;
76 };