Пример #1
0
/**
 * @brief	Append one string to another and return the result.
 * @param	s		a pointer to a leading null-terminated string to to which the other string will be appended.
 * @param	append	a pointer to a null-terminated string to be appended to the leading string.
 * @return	NULL if a memory allocation failure occurred, or a pointer to the resulting string on success.
 */
chr_t *ns_append(chr_t *s, chr_t *append) {

	chr_t *output = NULL;
	size_t alen, slen = 0;

	if (!append || !(alen = ns_length_get(append))) {
		log_pedantic("The append string appears to be empty.");
		return s;
	}

	// Allocate a new string if the existing string pointer is NULL.
	if (!s) {
		s = ns_dupe(append);
	} else if (!(slen = ns_length_get(s))) {
		ns_free(s);
		s = ns_dupe(append);
	}
	// Otherwise check the amount of available space in the buffer and if necessary allocate more.
	else if ((output = ns_alloc(slen + alen + 1))) {
		mm_copy(output, s, slen);
		mm_copy(output + slen, append, alen);
		ns_free(s);
		s = output;
	}

	return s;
}
Пример #2
0
/* Called when a new connection for this protocol found. */
static struct net_session * icmpv6_new(struct vrf *vrf, const struct sk_buff *skb,
		    				u32 dataoff, const struct netsession_tuple *orig,
		    				struct netsession_tuple *reply)
{
	static const u8 valid_new[] = {
		[ICMPV6_ECHO_REQUEST - 128] = 1,
		[ICMPV6_NI_QUERY - 128] = 1
	};
	s32 type = orig->dst.u.icmp.type - 128;

	if (type < 0 || type >= sizeof(valid_new) || !valid_new[type]) {
		/* Can't create a new ICMPv6 `conn' with this. */
		return NULL;
	}
	return ns_alloc(vrf, orig, reply, (struct ns_trans_addr *)(&skb->trans_addr));
}
Пример #3
0
/**
 * @brief	Return the fully qualified local file path of a stored mail message for a specified message number and server.
 * @param	number		the mail message id.
 * @param	server		the hostname of the server where the message data resides or if NULL, the default server.
 * @return	NULL on failure, or a pointer to a null-terminated string containing the absolute file path of the specified message.
 */
chr_t * mail_message_path(uint64_t number, chr_t *server) {

	chr_t *result;

	if (!(result = ns_alloc(1024))) {
		log_pedantic("Unable to allocate a buffer of %i bytes for the storage path.", 1024);
		return NULL;
	}

	// The default storage server.
	if (!server) {
		server = st_char_get(magma.storage.active);
	}

	// Build the message path.
	if ((snprintf(result, 1024, "%.*s/%s/%lu/%lu/%lu/%lu/%lu", st_length_int(magma.storage.root), st_char_get(magma.storage.root),
		server, number / 32768 / 32768 / 32768 / 32768, number / 32768 / 32768 / 32768 , number / 32768 / 32768,  number / 32768, number)) <= 0) {
		log_pedantic("Unable to create the message path.");
		ns_free(result);
		return NULL;
	}

	return result;
}
Пример #4
0
int
cdli_ns8390init()
{
	struct ndd *nddp;
	struct ns_8022 *filter;
	struct ns_user *ns_user;
	int	ret;

	printf("%s initializing pseudo-CDLI ns8390 driver\n", ns8390wdname);

	if (!(nddp = (struct ndd *)kalloc(sizeof(struct ndd))))
	{
		return(ENOMEM);
	}

	bzero((char *)nddp, sizeof(*nddp));
	nddp->ndd_name = ns8390wdname;
	nddp->ndd_unit = 0;
	nddp->ndd_type = NDD_ISO88023;
	nddp->d_ops = cdli_ns8390_dops;
	nddp->ndd_open = cdli_ns8390_open;
	nddp->ndd_close = cdli_ns8390_close;
	nddp->ndd_output = cdli_ns8390_output;
	nddp->ndd_ctl = cdli_ns8390_ctl;

	(void) dmx_init(nddp);

	if (ret = ns_attach(nddp)) /* Add network device driver */
	{
		goto bad;
	}

	if (!(filter = (struct ns_8022 *)kalloc(sizeof(*filter))))
	{
		return(ENOMEM);
	}

	bzero((char *)filter, sizeof(*filter));
	filter->filtertype = NS_STATUS_MASK;
	filter->dsap = 0x0;
	filter->orgcode[0] = '\0';
	filter->orgcode[1] = '\0';
	filter->orgcode[2] = '\0';
	filter->ethertype = NS_ETHERTYPE;

	eth_add_demuxer(nddp->ndd_type);

	if (!(ns_user = (struct ns_user *)kalloc(sizeof(struct ns_user))))
	{
		return(ENOMEM);
	}

	bzero((char *)ns_user, sizeof(struct ns_user));

	ns_user->isr = 0;

	if (ret = dmx_8022_add_filter(nddp, filter, ns_user)) /* Add demuxing filter */
	{
		goto bad;
	}

	ret = ns_alloc(nddp->ndd_name, &nddp);
 bad:
	return(ret);
}
Пример #5
0
/* Called when a new connection for this protocol found. */
static struct net_session *generic_new(struct vrf *vrf, const struct sk_buff *skb,
                        u32 dataoff, const struct netsession_tuple *orig,
                        struct netsession_tuple *reply)
{
	return ns_alloc(vrf, orig, reply, (struct ns_trans_addr *)(&skb->trans_addr));
}