Debian Codegraph @

tapset/linux/inet_sock.stp

raw
1 // inet_sock information tapset
2 // Copyright (C) 2006 IBM Corp.
3 // Copyright (C) 2006 Intel Corporation.
4 // Copyright (C) 2009-2024 Red Hat, Inc.
5 //
6 // This file is part of systemtap, and is free software. You can
7 // redistribute it and/or modify it under the terms of the GNU General
8 // Public License (GPL); either version 2, or (at your option) any
9 // later version.
10
11 /**
12 * sfunction inet_get_local_port - Provide local port number for a kernel socket
13 * @sock: pointer to the kernel socket
14 */
15 function inet_get_local_port:long(sock:long)
16 {
17 return @choose_defined(@inet_sock_cast(sock)->sk->__sk_common->skc_num,
18 # kernel >= 2.6.33
19 @choose_defined(@inet_sock_cast(sock)->inet_num,
20 # kernel >= 2.6.11
21 @choose_defined(@inet_sock_cast(sock)->num,
22 @inet_sock_cast(sock)->inet->num)))
23 }
24
25 /**
26 * sfunction inet_get_dest_port - Provide remote port number for a kernel socket
27 * @sock: pointer to the kernel socket
28 */
29 function inet_get_dest_port:long(sock:long)
30 {
31 port = @choose_defined(@inet_sock_cast(sock)->sk->__sk_common->skc_dport,
32 # kernel >= 3.8
33 @choose_defined(@inet_sock_cast(sock)->inet_dport,
34 # kernel >= 2.6.33
35 @choose_defined(@inet_sock_cast(sock)->dport,
36 # kernel >= 2.6.11
37 @inet_sock_cast(sock)->inet->dport)))
38 return ntohs(port)
39 }
40
41
42 /**
43 * sfunction inet_get_ip_source - Provide IP source address string for a kernel socket
44 *
45 * @sock: pointer to the kernel socket
46 *
47 */
48 function inet_get_ip_source:string(sock:long)
49 {
50 return format_ipaddr(__ip_sock_daddr(sock), __ip_sock_family(sock))
51 }
52
53
54 /**
55 * sfunction inet_get_ip_dest - Provide IP destination address string for a kernel socket
56 *
57 * @sock: pointer to the kernel socket
58 *
59 */
60 function inet_get_ip_dest:string(sock:long)
61
62 {
63 return format_ipaddr(__ip_sock_saddr(sock), __ip_sock_family(sock))
64 }
65
66
67 %(systemtap_v < "2.0" %?
68 // Turns a daddr as found in an inet_sock into a dotted ip string.
69 function daddr_to_string:string(daddr:long)
70 {
71 return format_ipaddr(daddr, @const("AF_INET"))
72 }
73 %)
74