Skip to content

Commit

Permalink
net: sockets: Implement gai_strerror()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
pfalcon authored and galak committed Mar 15, 2019
1 parent 4f42b11 commit 193d6c6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/net/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ static inline void zsock_freeaddrinfo(struct zsock_addrinfo *ai)
free(ai);
}

const char *zsock_gai_strerror(int errcode);

#define NI_NUMERICHOST 1
#define NI_NUMERICSERV 2
#define NI_NOFQDN 4
Expand Down Expand Up @@ -301,6 +303,11 @@ static inline void freeaddrinfo(struct zsock_addrinfo *ai)
zsock_freeaddrinfo(ai);
}

static inline const char *gai_strerror(int errcode)
{
return zsock_gai_strerror(errcode);
}

static inline int getnameinfo(const struct sockaddr *addr, socklen_t addrlen,
char *host, socklen_t hostlen,
char *serv, socklen_t servlen, int flags)
Expand Down
19 changes: 19 additions & 0 deletions subsys/net/lib/sockets/getaddrinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,23 @@ int zsock_getaddrinfo(const char *host, const char *service,
return ret;
}

#define ERR(e) case DNS_ ## e: return #e
const char *zsock_gai_strerror(int errcode)
{
switch (errcode) {
ERR(EAI_BADFLAGS);
ERR(EAI_NONAME);
ERR(EAI_AGAIN);
ERR(EAI_FAIL);
ERR(EAI_NODATA);
ERR(EAI_MEMORY);
ERR(EAI_SYSTEM);
ERR(EAI_SERVICE);

default:
return "EAI_UNKNOWN";
}
}
#undef ERR

#endif

0 comments on commit 193d6c6

Please sign in to comment.