smtpd does a lot of this sort of DNS lookup. If all you want is to map an IP address back to a domainname, this one line from /sys/src/cmd/upas/smtp/greylist.c:265 should suffice:
fqdn = csgetvalue(nil, "ip", nci->rsys, "dom", nil);
where nci->rsys is a string containing a dotted-quad address like
"135.104.9.82" for IPv4.
