1 /*
2 * Copyright (c) 2019 Linaro Limited
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <stdio.h>
8 #include <errno.h>
9 #include <zephyr/net/socket.h>
10
zsock_getnameinfo(const struct sockaddr * addr,socklen_t addrlen,char * host,socklen_t hostlen,char * serv,socklen_t servlen,int flags)11 int zsock_getnameinfo(const struct sockaddr *addr, socklen_t addrlen,
12 char *host, socklen_t hostlen,
13 char *serv, socklen_t servlen, int flags)
14 {
15 /* Both sockaddr_in & _in6 have same offsets for family and address. */
16 struct sockaddr_in *a = (struct sockaddr_in *)addr;
17
18 if (host != NULL) {
19 void *res = zsock_inet_ntop(a->sin_family, &a->sin_addr,
20 host, hostlen);
21
22 if (res == NULL) {
23 return DNS_EAI_SYSTEM;
24 }
25 }
26
27 if (serv != NULL) {
28 snprintk(serv, servlen, "%hu", ntohs(a->sin_port));
29 }
30
31 return 0;
32 }
33