- int r = snprintf(addr_buffer + scopeoffset, remain,
- "%%%"PRIu32"", scope);
- assert(r < *addr_buflen - scopeoffset);
+ char *scopeptr = addr_buffer + scopeoffset;
+ assert(remain >= IF_NAMESIZE+1/*%*/);
+ *scopeptr++= '%'; remain--;
+ char *ok = scope > UINT_MAX
+ ? 0 /* we can't pass it to if_indextoname then */
+ : if_indextoname(scope, scopeptr);
+ if (!ok) {
+ if (errno==ENXIO) {
+ /* fair enough, show it as a number then */
+ } else if (addrtext_our_errno(errno)) {
+ /* we use these for other purposes, urgh. */
+ perror("adns: adns_addr2text: if_indextoname"
+ " failed with unexpected error");
+ return EIO;
+ } else {
+ return errno;
+ }
+ int r = snprintf(scopeptr, remain,
+ "%"PRIu32"", scope);
+ assert(r < *addr_buflen - scopeoffset);
+ }