Skip to content

Commit 193d6c6

Browse files
pfalcongalak
authored andcommitted
net: sockets: Implement gai_strerror()
To save binary size, currently just returns textual name of error code, e.g. EAI_FAIL -> "EAI_FAIL". Based on real usecases, can be replaced with user-friendly message later. (Current usecase is to allow/help to elaborate sockets API by proof-of-concept porting existing socket apps). Signed-off-by: Paul Sokolovsky <[email protected]>
1 parent 4f42b11 commit 193d6c6

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

include/net/socket.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ static inline void zsock_freeaddrinfo(struct zsock_addrinfo *ai)
195195
free(ai);
196196
}
197197

198+
const char *zsock_gai_strerror(int errcode);
199+
198200
#define NI_NUMERICHOST 1
199201
#define NI_NUMERICSERV 2
200202
#define NI_NOFQDN 4
@@ -301,6 +303,11 @@ static inline void freeaddrinfo(struct zsock_addrinfo *ai)
301303
zsock_freeaddrinfo(ai);
302304
}
303305

306+
static inline const char *gai_strerror(int errcode)
307+
{
308+
return zsock_gai_strerror(errcode);
309+
}
310+
304311
static inline int getnameinfo(const struct sockaddr *addr, socklen_t addrlen,
305312
char *host, socklen_t hostlen,
306313
char *serv, socklen_t servlen, int flags)

subsys/net/lib/sockets/getaddrinfo.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,23 @@ int zsock_getaddrinfo(const char *host, const char *service,
222222
return ret;
223223
}
224224

225+
#define ERR(e) case DNS_ ## e: return #e
226+
const char *zsock_gai_strerror(int errcode)
227+
{
228+
switch (errcode) {
229+
ERR(EAI_BADFLAGS);
230+
ERR(EAI_NONAME);
231+
ERR(EAI_AGAIN);
232+
ERR(EAI_FAIL);
233+
ERR(EAI_NODATA);
234+
ERR(EAI_MEMORY);
235+
ERR(EAI_SYSTEM);
236+
ERR(EAI_SERVICE);
237+
238+
default:
239+
return "EAI_UNKNOWN";
240+
}
241+
}
242+
#undef ERR
243+
225244
#endif

0 commit comments

Comments
 (0)