#!/usr/bin/dtrace -CZs /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* * getipnodebyXXXX.d * * decode the calls to getipnodebyname (and therefore getipnodebyname()) and * getipnodebyaddr (and therefore getipnodebyaddr()). * * Usage: * If you are running on a 64 bit kernel and your target process is * 32 bit you *MUST* use the -32 flag to dtrace. * * dtrace -32 -CZs getipnodebyXXXX.d -c "getent hosts foo.bar" * * Chris.Gerhard@sun.com 2/12/2009 */ #pragma D option quiet #include pid$target::getipnodebyaddr:entry, pid$target::getipnodebyname:entry { self->errno = arg3; self->arg = (uint_t)arg0; self->len = (uint_t)arg1; } pid$target::getipnodebyaddr:return /self->len == 4/ { this->ax = (char *)copyin(self->arg, 4); printf("Look up: %d.%d.%d.%d:\n", this->ax[0], this->ax[1], this->ax[2], this->ax[3]); self->arg = 0; self->len = 0; this->ax = 0; } pid$target::getipnodebyaddr:return /self->len == 16/ { this->ss = (char *)copyin((uintptr_t)this->h_addr_ptr, this->h_addr_len); printf("look up: %x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x\n" this->ss[0], this->ss[1], this->ss[2], this->ss[3], this->ss[4], this->ss[5], this->ss[6], this->ss[7], this->ss[8], this->ss[9], this->ss[10], this->ss[11], this->ss[12], this->ss[13], this->ss[14], this->ss[15]); } pid$target::getipnodebyname:return { printf("Look up: %s:\n", copyinstr(self->arg)); self->arg = 0; } pid$target::getipnodebyaddr:return, pid$target::getipnodebyname:return /arg1 == 0/ { printf("%s failed. h_errno: %d\n", probefunc, *(int *)copyin(self->errno,sizeof(int))); self->errno = 0; } pid$target::getipnodebyaddr:return, pid$target::getipnodebyname:return /arg1 != 0/ { self->errno = 0; this->r = (struct hostent *)copyin(arg1, sizeof (struct hostent)); printf("Host: %s\n", copyinstr((uintptr_t)this->r->h_name)); this->h_alias = this->r->h_aliases; this->a = (char **)copyin((uintptr_t)this->h_alias, sizeof (char *)); this->h_alias_addr = this->a[0]; this->a = 0; this->h_addr_len = this->r->h_length; this->h_addr_list = this->r->h_addr_list; this->a = (char **) copyin((uintptr_t)this->h_addr_list, sizeof(char *)); this->h_addr_ptr = this->a[0]; this->a = 0; this->xa = 0; this->xs = 0; } #define ALIAS(X) \ pid$target::getipnodebyaddr:return, \ pid$target::getipnodebyname:return \ / arg1 != 0 && this->h_alias_addr != 0 / \ { \ this->s = copyinstr((uintptr_t)this->h_alias_addr); \ printf("\th_alias[%d]: %s\n", this->xs, \ this->s); \ this->s = 0; \ this->a = (char **)copyin((uintptr_t)this->h_alias, \ (this->xs+2) * sizeof (char *)); \ this->h_alias_addr = this->a[++this->xs]; \ this->a = 0 \ } #define ADDRESS(X) \ pid$target::getipnodebyaddr:return, \ pid$target::getipnodebyname:return \ / arg1 != 0 && this->h_addr_ptr != 0 && this->h_addr_len > 4 / \ { \ this->ss = (char *)copyin((uintptr_t)this->h_addr_ptr, \ this->h_addr_len); \ printf("\th_address[%d]: %x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x\n", this->xa, \ this->ss[0], this->ss[1], this->ss[2], this->ss[3], \ this->ss[4], this->ss[5], this->ss[6], this->ss[7], \ this->ss[8], this->ss[9], this->ss[10], this->ss[11], \ this->ss[12], this->ss[13], this->ss[14], this->ss[15]); \ } \ pid$target::getipnodebyaddr:return, \ pid$target::getipnodebyname:return \ / arg1 != 0 && this->h_addr_ptr != 0 && this->h_addr_len <= 4 / \ { \ this->ss = (char *)copyin((uintptr_t)this->h_addr_ptr, \ this->h_addr_len); \ printf("\th_address[%d]: %d.%d.%d.%d\n", this->xa, \ this->ss[0], this->ss[1], this->ss[2], this->ss[3]); \ } \ pid$target::getipnodebyaddr:return, \ pid$target::getipnodebyname:return \ / arg1 != 0 && this->h_addr_ptr != 0 / \ { \ this->ss = 0; \ this->a = (char **)copyin((uintptr_t)this->h_addr_list, \ (this->xa + 2) * sizeof (char *)); \ this->h_addr_ptr = this->a[++this->xa]; \ this->a = 0 \ } ALIAS() ALIAS() ALIAS() ALIAS() ALIAS() ALIAS() ALIAS() ALIAS() ALIAS() ALIAS() pid$target::getipnodebyaddr:return, pid$target::getipnodebyname:return / arg1 != 0 && this->h_alias_addr != 0 / { printf("\th_alias[%d] ... to many aliases returned", this->xs); } ADDRESS() ADDRESS() ADDRESS() ADDRESS() ADDRESS() pid$target::getipnodebyaddr:return, pid$target::getipnodebyname:return / arg1 != 0 && this->h_addr_ptr != 0 / { printf("\th_address[%d] ... to many addresses returned", this->xs); }