+ if ((strchr(cs_addr, '.')) && (!strchr(cs_addr, ':'))) {
+ int a1, a2, a3, a4;
+
+ sscanf(cs_addr, "%d.%d.%d.%d", &a1, &a2, &a3, &a4);
+ snprintf(tbuf, sizeof tbuf, "%d.%d.%d.%d.", a4, a3, a2, a1);
+ suffix_pos = strlen(tbuf);
+ }
+ else if ((!strchr(cs_addr, '.')) && (strchr(cs_addr, ':'))) {
+ int num_colons = 0;
+ int i = 0;
+ char workbuf[sizeof tbuf];
+ char *ptr;
+
+ /* tedious code to expand and reverse an IPv6 address */
+ safestrncpy(tbuf, cs_addr, sizeof tbuf);
+ num_colons = haschar(tbuf, ':');
+ if ((num_colons < 2) || (num_colons > 7))
+ goto finish_rbl; /* badly formed address */
+
+ /* expand the "::" shorthand */
+ while (num_colons < 7) {
+ ptr = strstr(tbuf, "::");
+ if (!ptr)
+ goto finish_rbl; /* badly formed address */
+
+ ++ptr;
+ strcpy(workbuf, ptr);
+ strcpy(ptr, ":");
+ strcat(ptr, workbuf);
+ ++num_colons;
+ }
+
+ /* expand to 32 hex characters with no colons */
+ strcpy(workbuf, tbuf);
+ strcpy(tbuf, "00000000000000000000000000000000");
+ for (i=0; i<8; ++i) {
+ char tokbuf[5];
+ extract_token(tokbuf, workbuf, i, ':', sizeof tokbuf);
+ memcpy(&tbuf[ (i*4) + (4-strlen(tokbuf)) ], tokbuf, strlen(tokbuf) );
+ }
+ if (strlen(tbuf) != 32) {
+ goto finish_rbl;
+ }
+
+ /* now reverse it and add dots */
+ strcpy(workbuf, tbuf);
+ for (i=0; i<32; ++i) {
+ tbuf[i*2] = workbuf[31-i];
+ tbuf[(i*2)+1] = '.';
+ }
+ tbuf[64] = 0;
+ suffix_pos = 64;
+ }
+ else {
+ goto finish_rbl; /* unknown address format */
+ }