⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 net.c

📁 linux进程跟踪的工具和源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
};#endif /* SOL_IPX */#ifdef SOL_RAWstatic struct xlat sockrawoptions[] = {#if defined(ICMP_FILTER)	{ ICMP_FILTER,		"ICMP_FILTER"	},#endif	{ 0,			NULL		},};#endif /* SOL_RAW */#ifdef SOL_PACKETstatic struct xlat sockpacketoptions[] = {	{ PACKET_ADD_MEMBERSHIP,	"PACKET_ADD_MEMBERSHIP"	},	{ PACKET_DROP_MEMBERSHIP,	"PACKET_DROP_MEMBERSHIP"},#if defined(PACKET_RECV_OUTPUT)	{ PACKET_RECV_OUTPUT,		"PACKET_RECV_OUTPUT"	},#endif#if defined(PACKET_RX_RING)	{ PACKET_RX_RING,		"PACKET_RX_RING"	},#endif#if defined(PACKET_STATISTICS)	{ PACKET_STATISTICS,		"PACKET_STATISTICS"	},#endif	{ 0,				NULL			},};#endif /* SOL_PACKET */#ifdef SOL_TCPstatic struct xlat socktcpoptions[] = {	{ TCP_NODELAY,	"TCP_NODELAY"	},	{ TCP_MAXSEG,	"TCP_MAXSEG"	},#if defined(TCP_CORK)	{ TCP_CORK,	"TCP_CORK"	},#endif	{ 0,		NULL		},};#endif /* SOL_TCP */#ifdef SOL_RAWstatic struct xlat icmpfilterflags[] = {#if defined(ICMP_ECHOREPLY)	{ (1<<ICMP_ECHOREPLY),		"ICMP_ECHOREPLY"	},#endif#if defined(ICMP_DEST_UNREACH)	{ (1<<ICMP_DEST_UNREACH),	"ICMP_DEST_UNREACH"	},#endif#if defined(ICMP_SOURCE_QUENCH)	{ (1<<ICMP_SOURCE_QUENCH),	"ICMP_SOURCE_QUENCH"	},#endif#if defined(ICMP_REDIRECT)	{ (1<<ICMP_REDIRECT),		"ICMP_REDIRECT"		},#endif#if defined(ICMP_ECHO)	{ (1<<ICMP_ECHO),		"ICMP_ECHO"		},#endif#if defined(ICMP_TIME_EXCEEDED)	{ (1<<ICMP_TIME_EXCEEDED),	"ICMP_TIME_EXCEEDED"	},#endif#if defined(ICMP_PARAMETERPROB)	{ (1<<ICMP_PARAMETERPROB),	"ICMP_PARAMETERPROB"	},#endif#if defined(ICMP_TIMESTAMP)	{ (1<<ICMP_TIMESTAMP),		"ICMP_TIMESTAMP"	},#endif#if defined(ICMP_TIMESTAMPREPLY)	{ (1<<ICMP_TIMESTAMPREPLY),	"ICMP_TIMESTAMPREPLY"	},#endif#if defined(ICMP_INFO_REQUEST)	{ (1<<ICMP_INFO_REQUEST),	"ICMP_INFO_REQUEST"	},#endif#if defined(ICMP_INFO_REPLY)	{ (1<<ICMP_INFO_REPLY),		"ICMP_INFO_REPLY"	},#endif#if defined(ICMP_ADDRESS)	{ (1<<ICMP_ADDRESS),		"ICMP_ADDRESS"		},#endif#if defined(ICMP_ADDRESSREPLY)	{ (1<<ICMP_ADDRESSREPLY),	"ICMP_ADDRESSREPLY"	},#endif	{ 0,				NULL			},};#endif /* SOL_RAW */voidprintsock(tcp, addr, addrlen)struct tcb *tcp;long addr;int addrlen;{	union {		char pad[128];		struct sockaddr sa;		struct sockaddr_in sin;		struct sockaddr_un sau;#ifdef HAVE_INET_NTOP		struct sockaddr_in6 sa6;#endif#if defined(LINUX) && defined(AF_IPX)		struct sockaddr_ipx sipx;#endif#ifdef AF_PACKET		struct sockaddr_ll ll;#endif#ifdef AF_NETLINK		struct sockaddr_nl nl;#endif	} addrbuf;	char string_addr[100];	if (addr == 0) {		tprintf("NULL");		return;	}	if (!verbose(tcp)) {		tprintf("%#lx", addr);		return;	}	if ((addrlen<2) || (addrlen>sizeof(addrbuf)))		addrlen=sizeof(addrbuf);	if (umoven(tcp, addr, addrlen, (char*)&addrbuf) < 0) {		tprintf("{...}");		return;	}	tprintf("{sin_family=");	printxval(addrfams, addrbuf.sa.sa_family, "AF_???");	tprintf(", ");	switch (addrbuf.sa.sa_family) {	case AF_UNIX:		if (addrlen==2) {			tprintf("<nil>");		} else if (addrbuf.sau.sun_path[0]) {			tprintf("path=\"%-.*s\"", addrlen-2, addrbuf.sau.sun_path);		} else {			tprintf("path=@%-.*s", addrlen-3, addrbuf.sau.sun_path+1);		}		break;	case AF_INET:		tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}",			ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));		break;#ifdef HAVE_INET_NTOP	case AF_INET6:		inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));		tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",				ntohs(addrbuf.sa6.sin6_port), string_addr,				addrbuf.sa6.sin6_flowinfo);#ifdef HAVE_SIN6_SCOPE_ID		{#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)		    int numericscope = 0;		    if (IN6_IS_ADDR_LINKLOCAL (&addrbuf.sa6.sin6_addr)			    || IN6_IS_ADDR_MC_LINKLOCAL (&addrbuf.sa6.sin6_addr)) {			char scopebuf[IFNAMSIZ + 1];						if (if_indextoname (addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)			    numericscope++;			else			    tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);		    } else			numericscope++;		    		    if (numericscope)#endif			tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);		}#endif		    break;#endif#if defined(AF_IPX) && defined(linux)	case AF_IPX:		{			int i;			tprintf("{sipx_port=htons(%u), ",					ntohs(addrbuf.sipx.sipx_port));			/* Yes, I know, this does not look too			 * strace-ish, but otherwise the IPX			 * addresses just look monstrous...			 * Anyways, feel free if you don't like			 * this way.. :) 			 */			tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));			for (i = 0; i<IPX_NODE_LEN; i++)				tprintf("%02x", addrbuf.sipx.sipx_node[i]);			tprintf("/[%02x]", addrbuf.sipx.sipx_type);		}		break;#endif /* AF_IPX && linux */#ifdef AF_PACKET	case AF_PACKET:		{			int i;			tprintf("proto=%#04x, if%d, pkttype=%d, addr(%d)={%d, ",					ntohs(addrbuf.ll.sll_protocol),					addrbuf.ll.sll_ifindex,					addrbuf.ll.sll_pkttype,					addrbuf.ll.sll_halen,					addrbuf.ll.sll_hatype);			for (i=0; i<addrbuf.ll.sll_addr[i]; i++) 				tprintf("%02x", addrbuf.ll.sll_addr[i]);		}		break;#endif /* AF_APACKET */#ifdef AF_NETLINLK	case AF_NETLINK:		tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);		break;#endif /* AF_NETLINK */	/* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5	AF_X25 AF_ROSE etc. still need to be done */	default:		tprintf("{sa_family=%u, sa_data=", addrbuf.sa.sa_family);		printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,			sizeof addrbuf.sa.sa_data);		break;	}	tprintf("}");}#if HAVE_SENDMSGstatic voidprintiovec(tcp, iovec, len)struct tcb *tcp;struct iovec *iovec;long   len;{	struct iovec *iov;	int i;	iov = (struct iovec *) malloc(len * sizeof *iov);	if (iov == NULL) {		fprintf(stderr, "No memory");		return;	}	if (umoven(tcp, (long)iovec,				len * sizeof *iov, (char *) iov) < 0) {		tprintf("%#lx", (unsigned long)iovec);	} else {		tprintf("[");		for (i = 0; i < len; i++) {			if (i)				tprintf(", ");			tprintf("{");			printstr(tcp, (long) iov[i].iov_base,					iov[i].iov_len);			tprintf(", %lu}", (unsigned long)iov[i].iov_len);		}		tprintf("]");	}	free((char *) iov);}static voidprintmsghdr(tcp, addr)struct tcb *tcp;long addr;{	struct msghdr msg;	if (umove(tcp, addr, &msg) < 0) {		tprintf("%#lx", addr);		return;	}	tprintf("{msg_name(%d)=", msg.msg_namelen);	printsock(tcp, (long)msg.msg_name, msg.msg_namelen);	tprintf(", msg_iov(%lu)=", (unsigned long)msg.msg_iovlen);	printiovec(tcp, msg.msg_iov, msg.msg_iovlen);#ifdef HAVE_MSG_CONTROL	tprintf(", msg_controllen=%lu", (unsigned long)msg.msg_controllen);	if (msg.msg_controllen) 		tprintf(", msg_control=%#lx, ", (unsigned long) msg.msg_control);	tprintf(", msg_flags=");	if (printflags(msg_flags, msg.msg_flags)==0)		tprintf("0");#else /* !HAVE_MSG_CONTROL */	tprintf("msg_accrights=%#lx, msg_accrightslen=%u",		(unsigned long) msg.msg_accrights, msg.msg_accrightslen);#endif /* !HAVE_MSG_CONTROL */	tprintf("}");}#endif /* HAVE_SENDMSG */intsys_socket(tcp)struct tcb *tcp;{	if (entering(tcp)) {		printxval(domains, tcp->u_arg[0], "PF_???");		tprintf(", ");		printxval(socktypes, tcp->u_arg[1], "SOCK_???");		tprintf(", ");		switch (tcp->u_arg[0]) {		case PF_INET:			printxval(protocols, tcp->u_arg[2], "IPPROTO_???");			break;#ifdef PF_IPX		case PF_IPX:			/* BTW: I don't believe this.. */			tprintf("[");			printxval(domains, tcp->u_arg[2], "PF_???");			tprintf("]");			break;#endif /* PF_IPX */		default:			tprintf("%lu", tcp->u_arg[2]);			break;		}	}	return 0;}intsys_so_socket(tcp)struct tcb *tcp;{	if (entering(tcp)) {		/* not sure really what these args are... but this		 * is how truss prints it		 */		tprintf("%ld, %ld, %ld, ",		  tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);		printpath(tcp, tcp->u_arg[3]);		tprintf(", %ld", tcp->u_arg[4]);	}	return 0;}intsys_so_socketpair(tcp)struct tcb *tcp;{	if (entering(tcp)) {	  	/* not sure what this arg is */		tprintf("0x%lx", tcp->u_arg[0]);	}	return 0;}intsys_bind(tcp)struct tcb *tcp;{	if (entering(tcp)) {		tprintf("%ld, ", tcp->u_arg[0]);		printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);		tprintf(", %lu", tcp->u_arg[2]);	}	return 0;}intsys_connect(tcp)struct tcb *tcp;{	return sys_bind(tcp);}intsys_listen(tcp)struct tcb *tcp;{	if (entering(tcp)) {		tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);	}	return 0;}intsys_accept(tcp)struct tcb *tcp;{	if (entering(tcp)) {		tprintf("%ld, ", tcp->u_arg[0]);	} else if (!tcp->u_arg[2])		tprintf("%#lx, NULL", tcp->u_arg[1]);	else {		if (tcp->u_arg[1] == 0 || syserror(tcp)) {			tprintf("%#lx", tcp->u_arg[1]);		} else {			printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);		}		tprintf(", ");		printnum(tcp, tcp->u_arg[2], "%lu");	}	return 0;}intsys_send(tcp)struct tcb *tcp;{	if (entering(tcp)) {		tprintf("%ld, ", tcp->u_arg[0]);		printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);		tprintf(", %lu, ", tcp->u_arg[2]);		/* flags */		if (printflags(msg_flags, tcp->u_arg[3]) == 0)			tprintf("0");	}	return 0;}intsys_sendto(tcp)struct tcb *tcp;{	if (entering(tcp)) {		tprintf("%ld, ", tcp->u_arg[0]);		printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);		tprintf(", %lu, ", tcp->u_arg[2]);		/* flags */		if (printflags(msg_flags, tcp->u_arg[3]) == 0)			tprintf("0");		/* to address */		tprintf(", ");		printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);		/* to length */		tprintf(", %lu", tcp->u_arg[5]);	}	return 0;}#ifdef HAVE_SENDMSGintsys_sendmsg(tcp)struct tcb *tcp;{	if (entering(tcp)) {		tprintf("%ld, ", tcp->u_arg[0]);		printmsghdr(tcp, tcp->u_arg[1]);		/* flags */		tprintf(", ");		if (printflags(msg_flags, tcp->u_arg[2]) == 0)			tprintf("0");	}	return 0;}#endif /* HAVE_SENDMSG */intsys_recv(tcp)struct tcb *tcp;{	if (entering(tcp)) {		tprintf("%ld, ", tcp->u_arg[0]);	} else {		if (syserror(tcp))			tprintf("%#lx", tcp->u_arg[1]);		else			printstr(tcp, tcp->u_arg[1], tcp->u_rval);		tprintf(", %lu, ", tcp->u_arg[2]);		if (printflags(msg_flags, tcp->u_arg[3]) == 0)			tprintf("0");	}	return 0;}intsys_recvfrom(tcp)struct tcb *tcp;{	int fromlen;	if (entering(tcp)) {		tprintf("%ld, ", tcp->u_arg[0]);	} else {		if (syserror(tcp)) {			tprintf("%#lx, %lu, %lu, %#lx, %#lx",				tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],				tcp->u_arg[4], tcp->u_arg[5]);			return 0;		}		/* buf */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -