This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tapsets/9871] use @cast() instead of embedded-c whereever possible


------- Additional Comments From mjw at redhat dot com  2009-02-27 14:46 -------
I did one small rewrite of tapset/inet_sock.stp, which is nicely smaller now. It
does still need a small tidbit of embedded C because we cannot easily cast
between basic types/unions, see the new daddr_to_string.

function inet_get_local_port:long(sock:long)
{
%(kernel_v < "2.6.21" %?
  port = @cast(sock, "inet_sock", "kernel")->inet->num;
%:
  port = @cast(sock, "inet_sock", "kernel")->num;
%)
  return port;
}

// Get IP source address string given a pointer to a kernel socket.
function inet_get_ip_source:string(sock:long)
{
%(kernel_v < "2.6.21" %?
  daddr = @cast(sock, "inet_sock", "kernel")->inet->daddr;
%:
  daddr = @cast(sock, "inet_sock", "kernel")->daddr;
%)
  return daddr_to_string(daddr);
}

// Turns a daddr as found in an inet_sock into a dotted ip string.
function daddr_to_string:string(daddr:long)
%{ /* pure */
	union { __u32 d; unsigned char addr[4]; } u;
	u.d = THIS->daddr;
	sprintf(THIS->__retvalue, "%d.%d.%d.%d",
			u.addr[0], u.addr[1], u.addr[2], u.addr[3]);
%}

-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=9871

------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]