si_item_t *
si_item_call(struct si_mod_s *si, int call, const char *str1, const char *str2, const char *str3, uint32_t num1, uint32_t num2, uint32_t *err)
{
	if (si == NULL) return NULL;

	switch (call)
	{
		case SI_CALL_USER_BYNAME: return si_user_byname(si, str1);
		case SI_CALL_USER_BYUID: return si_user_byuid(si, (uid_t)num1);
		case SI_CALL_GROUP_BYNAME: return si_group_byname(si, str1);
		case SI_CALL_GROUP_BYGID: return si_group_bygid(si, (gid_t)num1);
		case SI_CALL_GROUPLIST: return si_grouplist(si, str1, (int) num1);
		case SI_CALL_ALIAS_BYNAME: return si_alias_byname(si, str1);
		case SI_CALL_HOST_BYNAME: return si_host_byname(si, str1, num1, str3, err);
		case SI_CALL_HOST_BYADDR: return si_host_byaddr(si, (void *)str1, num1, str3, err);
		case SI_CALL_NETWORK_BYNAME: return si_network_byname(si, str1);
		case SI_CALL_NETWORK_BYADDR: return si_network_byaddr(si, num1);
		case SI_CALL_SERVICE_BYNAME: return si_service_byname(si, str1, str2);
		case SI_CALL_SERVICE_BYPORT: return si_service_byport(si, num1, str2);
		case SI_CALL_PROTOCOL_BYNAME: return si_protocol_byname(si, str1);
		case SI_CALL_PROTOCOL_BYNUMBER: return si_protocol_bynumber(si, num1);
		case SI_CALL_RPC_BYNAME: return si_network_byname(si, str1);
		case SI_CALL_RPC_BYNUMBER: return si_rpc_bynumber(si, num1);
		case SI_CALL_FS_BYSPEC: return si_fs_byspec(si, str1);
		case SI_CALL_FS_BYFILE: return si_fs_byfile(si, str1);
		case SI_CALL_NAMEINFO: return si_nameinfo(si, (const struct sockaddr *)str1, num1, str3, err);
		case SI_CALL_IPNODE_BYNAME: return si_ipnode_byname(si, (const char *)str1, num1, num2, str3, err);
		case SI_CALL_MAC_BYNAME: return si_mac_byname(si, (const char *)str1);
		case SI_CALL_MAC_BYMAC: return si_mac_bymac(si, (const char *)str1);

		/* Support for DNS async calls */
		case SI_CALL_DNS_QUERY:
		case SI_CALL_DNS_SEARCH:
		{
			if (si->vtable->sim_item_call == NULL) return NULL;
			return si->vtable->sim_item_call(si, call, str1, str2, str3, num1, num2, err);
		}

		default: return NULL;
	}

	return NULL;
}
Beispiel #2
0
int
_gai_serv_to_port(const char *serv, uint32_t proto, uint16_t *port)
{
	si_item_t *item;
	struct servent *s;
	const char *protoname = NULL;

	if (_gai_numericserv(serv, port)) return 0;

	if (proto == IPPROTO_UDP) protoname = "udp";
	if (proto == IPPROTO_TCP) protoname = "tcp";

	item = si_service_byname(si_search(), serv, protoname);
	if (item == NULL) return -1;

	s = (struct servent *)((uintptr_t)item + sizeof(si_item_t));
	if (port) *port = ntohs(s->s_port);
	si_item_release(item);

	return 0;
}