Esempio n. 1
0
/*
 * rfc1035NamePack()
 * 
 * Packs a name into a buffer.  Names are packed as a
 * sequence of labels, terminated with NULL label.
 * Note message compression is not supported here.
 * Returns number of octets packed.
 */
static int
rfc1035NamePack(char *buf, size_t sz, const char *name)
{
    int off = 0;
    char *copy = xstrdup(name);
    char *t;
    /*
     * NOTE: use of strtok here makes names like foo....com valid.
     */
    for (t = strtok(copy, "."); t; t = strtok(NULL, "."))
	off += rfc1035LabelPack(buf + off, sz - off, t);
    xfree(copy);
    off += rfc1035LabelPack(buf + off, sz - off, NULL);
    assert(off <= sz);
    return off;
}
Esempio n. 2
0
/*
* rfc1035NamePack()
* 
* Packs a name into a buffer.  Names are packed as a
* sequence of labels, terminated with NULL label.
* Note message compression is not supported here.
* Returns number of octets packed.
*/
static int rfc1035NamePack(char *buf, size_t sz, const char *name)
{
	const char *myname = "rfc1035NamePack";
	int off = 0;
	char *copy, *ptr;
	char *t;

	copy = acl_mystrdup(name);
	/*
	* NOTE: use of strtok here makes names like foo....com valid.
	*/
	ptr = copy;
	for (t = acl_mystrtok(&ptr, "."); t; t = acl_mystrtok(&ptr, "."))
		off += rfc1035LabelPack(buf + off, sz - off, t);
	acl_myfree(copy);
	off += rfc1035LabelPack(buf + off, sz - off, NULL);
	if (off > (int) sz)
		acl_msg_fatal("%s: off(%d) > sz(%d)", myname, off, sz);
	return off;
}