+char *formathaddress(struct sockaddr *name, socklen_t namelen)
+{
+ static char buf[128];
+ struct sockaddr_in *v4;
+ struct sockaddr_in6 *v6;
+
+ switch(name->sa_family) {
+ case AF_INET:
+ v4 = (struct sockaddr_in *)name;
+ if(!inet_ntop(AF_INET, &v4->sin_addr, buf, sizeof(buf)))
+ return(NULL);
+ return(buf);
+ case AF_INET6:
+ v6 = (struct sockaddr_in6 *)name;
+ if(IN6_IS_ADDR_V4MAPPED(&v6->sin6_addr)) {
+ if(!inet_ntop(AF_INET, ((char *)&v6->sin6_addr) + 12, buf, sizeof(buf)))
+ return(NULL);
+ } else {
+ if(!inet_ntop(AF_INET6, &v6->sin6_addr, buf, sizeof(buf)))
+ return(NULL);
+ }
+ return(buf);
+ default:
+ errno = EPFNOSUPPORT;
+ return(NULL);
+ }
+}
+