|
1 | | -/* |
2 | | - * Copyright (C) 2015 - 2018, IBEROXARXA SERVICIOS INTEGRALES, S.L. |
3 | | - * Copyright (C) 2015 - 2018, Jaume Olivé Petrus ([email protected]) |
4 | | - * |
5 | | - * All rights reserved. |
6 | | - * |
7 | | - * Redistribution and use in source and binary forms, with or without |
8 | | - * modification, are permitted provided that the following conditions are met: |
9 | | - * |
10 | | - * * Redistributions of source code must retain the above copyright |
11 | | - * notice, this list of conditions and the following disclaimer. |
12 | | - * * Redistributions in binary form must reproduce the above copyright |
13 | | - * notice, this list of conditions and the following disclaimer in the |
14 | | - * documentation and/or other materials provided with the distribution. |
15 | | - * * Neither the name of the <organization> nor the |
16 | | - * names of its contributors may be used to endorse or promote products |
17 | | - * derived from this software without specific prior written permission. |
18 | | - * * The WHITECAT logotype cannot be changed, you can remove it, but you |
19 | | - * cannot change it in any way. The WHITECAT logotype is: |
20 | | - * |
21 | | - * /\ /\ |
22 | | - * / \_____/ \ |
23 | | - * /_____________\ |
24 | | - * W H I T E C A T |
25 | | - * |
26 | | - * * Redistributions in binary form must retain all copyright notices printed |
27 | | - * to any local or remote output device. This include any reference to |
28 | | - * Lua RTOS, whitecatboard.org, Lua, and other copyright notices that may |
29 | | - * appear in the future. |
30 | | - * |
31 | | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
32 | | - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
33 | | - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
34 | | - * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY |
35 | | - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
36 | | - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
37 | | - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
38 | | - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
39 | | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
40 | | - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
41 | | - * |
42 | | - * Lua RTOS getnameinfo implementation |
43 | | - * |
44 | | - */ |
45 | | - |
46 | | -/* |
47 | | - * IMPORTANT NOTICE: |
48 | | - * |
49 | | - * In Lua RTOS the getnameinfo function implementation is incomplete. |
50 | | - * We must found a method to do a reverse DNS query in LWIP to full |
51 | | - * implement this function. |
52 | | - * |
53 | | - */ |
54 | | - |
55 | 1 | #include "netdb.h" |
56 | | -#include "lwip/ip_addr.h" |
57 | 2 | #include "compat.h" |
58 | 3 |
|
59 | | -int |
60 | | -getnameinfo(const struct sockaddr *sa, socklen_t salen, |
61 | | - char *host, size_t hostlen, |
62 | | - char *serv, size_t servlen, int flags) |
63 | | -{ |
64 | | - if (flags & ~(NI_NUMERICHOST | NI_NUMERICSERV)) { |
65 | | - return EAI_BADFLAGS; |
66 | | - } |
67 | | - |
68 | | - const struct sockaddr_in *sinp = (const struct sockaddr_in *) sa; |
69 | | - |
70 | | - switch (sa->sa_family) { |
71 | | - case AF_INET: |
72 | | - if (flags & NI_NUMERICHOST) { |
73 | | - if (inet_ntop (AF_INET, &sinp->sin_addr, host, hostlen) == NULL) { |
74 | | - return EAI_OVERFLOW; |
75 | | - } |
76 | | - } |
77 | | - |
78 | | - if (flags & NI_NUMERICSERV) { |
79 | | - if (snprintf(serv, servlen, "%d", ntohs (sinp->sin_port)) < 0) { |
80 | | - return EAI_OVERFLOW; |
81 | | - } |
82 | | - } |
83 | | - |
84 | | - break; |
85 | | - } |
86 | | - |
87 | | - |
88 | | - return 0; |
| 4 | +int getnameinfo(const struct sockaddr *sa, socklen_t salen, |
| 5 | + char *host, size_t hostlen, |
| 6 | + char *serv, size_t servlen, int flags) { |
| 7 | + if (flags & ~(NI_NUMERICHOST | NI_NUMERICSERV)) { |
| 8 | + return EAI_BADFLAGS; |
| 9 | + } |
| 10 | + |
| 11 | + const struct sockaddr_in* sinp = (const struct sockaddr_in*) sa; |
| 12 | + |
| 13 | + if (sa->sa_family == AF_INET) { |
| 14 | + if (flags & NI_NUMERICHOST) { |
| 15 | + if (inet_ntop(AF_INET, &sinp->sin_addr, host, hostlen) == NULL) { |
| 16 | + return EAI_OVERFLOW; |
| 17 | + } |
| 18 | + } |
| 19 | + if (flags & NI_NUMERICSERV) { |
| 20 | + if (snprintf(serv, servlen, "%d", ntohs(sinp->sin_port)) < 0) { |
| 21 | + return EAI_OVERFLOW; |
| 22 | + } |
| 23 | + } |
| 24 | + } else { |
| 25 | + return EAI_FAMILY; |
| 26 | + } |
| 27 | + return 0; |
89 | 28 | } |
0 commit comments