Exemplo n.º 1
0
static int read_iface_prefix(const char *ip_str, int is_ipv6)
{
	uint8_t family = is_ipv6 ? AF_INET6 : AF_INET;

	char buf[16384];
	unsigned int len;

	struct {
		struct nlmsghdr nlhdr;
		struct ifaddrmsg addrmsg;
	} msg;

	struct nlmsghdr *retmsg;

	int sock = SAFE_SOCKET(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);

	memset(&msg, 0, sizeof(msg));
	msg.nlhdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
	msg.nlhdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT;
	msg.nlhdr.nlmsg_type = RTM_GETADDR;
	msg.addrmsg.ifa_family = family;

	SAFE_SEND(1, sock, &msg, msg.nlhdr.nlmsg_len, 0);
	len = recv(sock, buf, sizeof(buf), 0);
	retmsg = (struct nlmsghdr *)buf;

	while NLMSG_OK(retmsg, len) {
		char ifname[IFNAMSIZ];
		struct ifaddrmsg *retaddr;
		struct rtattr *retrta;
		char pradd[128];
		int attlen;

		retaddr = (struct ifaddrmsg *)NLMSG_DATA(retmsg);
		retrta = (struct rtattr *)IFA_RTA(retaddr);
		attlen = IFA_PAYLOAD(retmsg);

		while RTA_OK(retrta, attlen) {
			if (retrta->rta_type == IFA_ADDRESS) {
				inet_ntop(family, RTA_DATA(retrta), pradd,
					  sizeof(pradd));

				if_indextoname(retaddr->ifa_index, ifname);

				if (!strcmp(pradd, ip_str)) {
					prefix = retaddr->ifa_prefixlen;
					iface = strdup(ifname);
					return 0;
				}
			}
			retrta = RTA_NEXT(retrta, attlen);
		}
		retmsg = NLMSG_NEXT(retmsg, len);
	}

	return -1;
}
Exemplo n.º 2
0
void ProfilerSocket::SendNetworkMessage( NetworkMessage nm )
{
	UINT16 mess = nm;
	SAFE_SEND( _s, mess );

	if ( !_bSentApplicationID )
	{
		if ( nm != INITIALIZE )
			SendUINT32( _nApplicationID );

		_bSentApplicationID = true;
	}
}
Exemplo n.º 3
0
void ProfilerSocket::SendFunctionID( FunctionID fid )
{
	SAFE_SEND( _s, fid );
}
Exemplo n.º 4
0
void ProfilerSocket::SendThreadID( ThreadID tid )
{
	SAFE_SEND( _s, tid );
}
Exemplo n.º 5
0
void ProfilerSocket::SendAppDomainID( AppDomainID aid )
{
	SAFE_SEND( _s, aid );
}
Exemplo n.º 6
0
void ProfilerSocket::SendUINT64( UINT64 ui )
{
	SAFE_SEND( _s, ui );
}
Exemplo n.º 7
0
void ProfilerSocket::SendUINT32( UINT32 ui )
{
	SAFE_SEND( _s, ui );
}
Exemplo n.º 8
0
void ProfilerSocket::SendBool( bool b )
{
	SAFE_SEND( _s, b );
}