Peter Cudhea
2008-Oct-22 21:03 UTC
[dtrace-discuss] Looking for: Coding example for inet_ntoa equiv for user-land IP addresses
I am writing a Dtrace script for a context (Solaris 10) in which the built-in functions inet_ntoa and inet_ntoa6 are not available. The input is a userland address to a sockddr_in structure. Does anyone have a pointer to a working example of D code that takes a userland pointer to a sockaddr or ip address, dereferences it using copyin, and formats it using strjoin into "dotted decimal" form? The closest I have found is the magic in Brendan''s tcpsnoop to do something similar with the kernel-side IP addresses. This is useful. I am hoping for something even closer to what I need. Peter
Adam Leventhal
2008-Oct-22 21:49 UTC
[dtrace-discuss] Looking for: Coding example for inet_ntoa equiv for user-land IP addresses
Peter, Just backport the inet_ntoa() and inet_ntoa6() subroutines. I don''t think it''s worth faking something up. Adam On Wed, Oct 22, 2008 at 05:03:09PM -0400, Peter Cudhea wrote:> I am writing a Dtrace script for a context (Solaris 10) in which the > built-in functions inet_ntoa and inet_ntoa6 are not available. The > input is a userland address to a sockddr_in structure. > > Does anyone have a pointer to a working example of D code that takes a > userland pointer to a sockaddr or ip address, dereferences it using > copyin, and formats it using strjoin into "dotted decimal" form? > > The closest I have found is the magic in Brendan''s tcpsnoop to do > something similar with the kernel-side IP addresses. This is useful. > I am hoping for something even closer to what I need. > > Peter > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org-- Adam Leventhal, Fishworks http://blogs.sun.com/ahl
Robert Milkowski
2010-Jan-15 11:04 UTC
[dtrace-discuss] Looking for: Coding example for inet_ntoa equiv for user-land IP addresses
Hi,
Adam - has it been actually backported yet? It doesn''t look like it
has.
btw: as a workaround one might for example do:
<pre>
syscall::getpeername:entry
/ pid == $1 /
{
self->in = 1;
self->arg0 = arg0; /* int s */
self->arg1 = arg1; /* struct sockaddr * */
self->arg2 = arg2; /* size_t len */
}
<pre>
syscall::getpeername:return
/ self->in /
{
this->len = *(socklen_t *) copyin((uintptr_t)self->arg2,
sizeof(socklen_t));
this->socks = (struct sockaddr *) copyin((uintptr_t)self->arg1,
this->len);
this->hport = (uint_t)(this->socks->sa_data[0]);
this->lport = (uint_t)(this->socks->sa_data[1]);
this->hport <<= 8;
this->port = this->hport + this->lport;
this->a1 = lltostr((uint_t)this->socks->sa_data[2]);
this->a2 = lltostr((uint_t)this->socks->sa_data[3]);
this->a3 = lltostr((uint_t)this->socks->sa_data[4]);
this->a4 = lltostr((uint_t)this->socks->sa_data[5]);
this->s1 = strjoin(this->a1, ".");
this->s2 = strjoin(this->s1, this->a2);
this->s1 = strjoin(this->s2, ".");
this->s2 = strjoin(this->s1, this->a3);
this->s1 = strjoin(this->s2, ".");
this->client_ip = strjoin(this->s1, this->a4);
</pre>
--
Robert Milkowski
http://milek.blogspot.com
--
This message posted from opensolaris.org