Home | History | Annotate | Line # | Download | only in util
      1 /*	$NetBSD: sane_sockaddr_to_hostaddr.c,v 1.3 2026/05/09 18:49:23 christos Exp $	*/
      2 
      3 /*++
      4 /* NAME
      5 /*	sane_sockaddr_to_hostaddr 3
      6 /* SUMMARY
      7 /*	Sanitize IPv4 in IPv6 address
      8 /* SYNOPSIS
      9 /*	#include <myaddrinfo.h>
     10 /*
     11 /*	int	sane_sockaddr_to_hostaddr(
     12 /*	struct sockaddr *addr_storage,
     13 /*	SOCKADDR_SIZE addr_storage_len,
     14 /*	MAI_HOSTADDR_STR *addr_buf,
     15 /*	MAI_SERVPORT_STR *port_buf,
     16 /*	int socktype)
     17 /* DESCRIPTION
     18 /*	sane_sockaddr_to_hostaddr() converts a V4mapped IPv6 address to
     19 /*	IPv4 form, but only if IPv4 support is available. It then invokes
     20 /*	sockaddr_to_hostaddr() to convert the result to human-readable
     21 /*	form.
     22 /*
     23 /*	NOTE: The V4mapped IPv6 conversion to IPv4 applies to both inputs
     24 /*	and output.
     25 /* LICENSE
     26 /* .ad
     27 /* .fi
     28 /*	The Secure Mailer license must be distributed with this software.
     29 /* AUTHOR(S)
     30 /*	Wietse Venema
     31 /*	IBM T.J. Watson Research
     32 /*	P.O. Box 704
     33 /*	Yorktown Heights, NY 10598, USA
     34 /*
     35 /*	Wietse Venema
     36 /*	Google, Inc.
     37 /*	111 8th Avenue
     38 /*	New York, NY 10011, USA
     39 /*
     40 /*	Wietse Venema
     41 /*	porcupine.org
     42 /*--*/
     43 
     44  /*
     45   * System library.
     46   */
     47 #include <sys_defs.h>
     48 
     49  /*
     50   * Utility library.
     51   */
     52 #include <myaddrinfo.h>
     53 #include <normalize_v4mapped_addr.h>
     54 
     55 /* sane_sockaddr_to_hostaddr - sanitize IPV4 in IPV6 address */
     56 
     57 int     sane_sockaddr_to_hostaddr(struct sockaddr *addr_storage,
     58 				          SOCKADDR_SIZE *addr_storage_len,
     59 				          MAI_HOSTADDR_STR *addr_buf,
     60 				          MAI_SERVPORT_STR *port_buf,
     61 				          int socktype)
     62 {
     63 #ifdef AF_INET6
     64     if (addr_storage->sa_family == AF_INET6)
     65 	normalize_v4mapped_sockaddr(addr_storage, addr_storage_len);
     66 #endif
     67     return (sockaddr_to_hostaddr(addr_storage, *addr_storage_len,
     68 				 addr_buf, port_buf, socktype));
     69 }
     70