* replaced by a 5 character string: YYXXX
* Where 'YY' represents the server, and 'XXX' the nick on that server.
*
- * 'YYXXX' should not interfer with the input parser, and therefore is
+ * 'YYXXX' should not interfere with the input parser, and therefore is
* not allowed to contain spaces or a ':'.
* Also, 'YY' can't start with a '+' because of m_server().
*
* @param[out] buf Output buffer to write to.
* @param[in] addr IP address to encode.
* @param[in] count Number of bytes writable to \a buf.
+ * @param[in] v6_ok If non-zero, peer understands base-64 encoded IPv6 addresses.
*/
const char* iptobase64(char* buf, const struct irc_in_addr* addr, unsigned int count, int v6_ok)
{
memset(addr, 0, sizeof(*addr));
if (strlen(input) == 6) {
unsigned int in = base64toint(input);
- addr->in6_16[6] = htons(in >> 16);
- addr->in6_16[7] = htons(in & 65535);
+ /* An all-zero address should stay that way. */
+ if (in) {
+ addr->in6_16[5] = htons(65535);
+ addr->in6_16[6] = htons(in >> 16);
+ addr->in6_16[7] = htons(in & 65535);
+ }
} else {
unsigned int pos = 0;
do {
if (*input == '_') {
unsigned int left;
- for (left = (25 - strlen(input)) / 3; left; left--)
+ for (left = (25 - strlen(input)) / 3 - pos; left; left--)
addr->in6_16[pos++] = 0;
input++;
} else {
accum = (accum << NUMNICKLOG) | convert2n[(unsigned char)*input++];
accum = (accum << NUMNICKLOG) | convert2n[(unsigned char)*input++];
addr->in6_16[pos++] = ntohs(accum);
- input += 3;
}
} while (pos < 8);
}