From: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v8 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
Date: Wed, 14 Oct 2015 14:27:10 +0800 [thread overview]
Message-ID: <1444804030.4685.6.camel@G08FNSTD140232> (raw)
In-Reply-To: <561CE0B0.2000801@oracle.com>
Hi,
On Tue, 2015-10-13 at 13:45 +0300, Alexey Kodanev wrote:
> Hi,
> On 10/08/2015 02:29 PM, Zeng Linggang wrote:
> > +#include <errno.h>
> > +#include "test.h"
> > +#include "safe_net.h"
> > +
> > +char *tst_sock_addr(const struct sockaddr *sa, socklen_t salen, char *res,
> > + size_t len)
> > +{
> > + char portstr[8];
> > +
> > + switch (sa->sa_family) {
> > +
> > + case AF_INET: {
> > + struct sockaddr_in *sin = (struct sockaddr_in *)sa;
> > +
> > + if (!inet_ntop(AF_INET, &sin->sin_addr, res, len))
> > + return NULL;
> > +
> > + if (ntohs(sin->sin_port) != 0) {
> > + snprintf(portstr, sizeof(portstr), ":%d",
> > + ntohs(sin->sin_port));
> > + strcat(res, portstr);
> > + }
> > +
> > + return res;
> > + }
> > +
> > + case AF_INET6: {
> > + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
> > +
> > + res[0] = '[';
> > + if (!inet_ntop(AF_INET6, &sin6->sin6_addr, res + 1, len - 1))
> > + return NULL;
> > +
> > + if (ntohs(sin6->sin6_port) != 0) {
> > + snprintf(portstr, sizeof(portstr), "]:%d",
> > + ntohs(sin6->sin6_port));
> > + strcat(res, portstr);
> > + return res;
> > + }
> > +
> > + return res + 1;
> > + }
> > +
> > + case AF_UNIX: {
> > + struct sockaddr_un *unp = (struct sockaddr_un *)sa;
> > +
> > + if (unp->sun_path[0] == '\0')
> > + strcpy(res, "(no pathname bound)");
> > + else
> > + snprintf(res, len, "%s", unp->sun_path);
> > +
> > + return res;
> > + }
> > +
> > + default: {
> > + snprintf(res, len,
> > + "sock_ntop: unknown AF_xxx: %d, len: %d",
> > + sa->sa_family, salen);
> > +
> > + return res;
> > + }
> > +
> > + }
> > +
> > + return NULL;
>
> The last return is redundant here.
>
Yep.
> > +}
> > +
> > +int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void),
> > + int domain, int type, int protocol)
> > +{
> > + int rval;
> > +
> > + rval = socket(domain, type, protocol);
> > +
> > + if (rval < 0) {
> > + tst_brkm(TBROK | TERRNO, cleanup_fn,
> > + "%s:%d: socket(%d, %d, %d) failed", file, lineno,
> > + domain, type, protocol);
> > + }
> > +
> > + return rval;
> > +}
> > +
> > +int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void),
> > + int socket, const struct sockaddr *address,
> > + socklen_t address_len)
> > +{
> > + int i;
> > + char buf[128];
> > +
> > + for (i = 0; i < 120; i++) {
> > + if (!bind(socket, address, address_len)) {
> > + tst_resm(TINFO, "bind is OK now");
>
> I doubt that we need to print "bind is OK now"... the other library
> functions don't print anything on success.
"Silence is golden" :)
>
> Otherwise it looks good.
>
> Also, could you please send a patch that renames asapi_04/05/06 to
> asapi_01/02/03?
Hmm, OK. I will rename them in the next version(V9).
Thank you very much.
Best regards,
Zeng
>
> Best regards,
> Alexey
>
next prev parent reply other threads:[~2015-10-14 6:27 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-07 10:47 [LTP] [PATCH v7 1/7] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
2015-10-07 10:47 ` [LTP] [PATCH v7 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
2015-10-07 13:07 ` Cyril Hrubis
2015-10-08 1:34 ` Zeng Linggang
2015-10-07 13:28 ` Cyril Hrubis
2015-10-08 11:29 ` [LTP] [PATCH v8 1/7] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
2015-10-08 11:29 ` [LTP] [PATCH v8 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
2015-10-13 10:45 ` Alexey Kodanev
2015-10-14 6:27 ` Zeng Linggang [this message]
2015-10-14 8:21 ` [LTP] [PATCH v9 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
2015-10-14 8:21 ` [LTP] [PATCH v9 2/8] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
2015-10-14 8:21 ` [LTP] [PATCH v9 3/8] lib6/asapi_04.c: Cleanup Zeng Linggang
2015-10-14 8:21 ` [LTP] [PATCH v9 4/8] lib6/asapi_05.c: Cleanup Zeng Linggang
2015-10-14 8:21 ` [LTP] [PATCH v9 5/8] lib6/asapi_06.c: Cleanup Zeng Linggang
2015-10-14 8:21 ` [LTP] [PATCH v9 6/8] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
2015-10-20 8:07 ` Alexey Kodanev
2015-10-21 2:47 ` Zeng Linggang
2015-10-21 3:15 ` [LTP] [PATCH v10 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
2015-10-21 3:15 ` [LTP] [PATCH v10 2/8] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
2015-10-21 3:15 ` [LTP] [PATCH v10 3/8] lib6/asapi_04.c: Cleanup Zeng Linggang
2015-10-21 3:15 ` [LTP] [PATCH v10 4/8] lib6/asapi_05.c: Cleanup Zeng Linggang
2015-10-21 3:15 ` [LTP] [PATCH v10 5/8] lib6/asapi_06.c: Cleanup Zeng Linggang
2015-10-21 3:15 ` [LTP] [PATCH v10 6/8] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
2015-10-21 3:15 ` [LTP] [PATCH v10 7/8] lib6: Rename Zeng Linggang
2015-10-21 3:15 ` [LTP] [PATCH v10 8/8] ipv6_lib: Add it into default Zeng Linggang
2015-10-22 11:12 ` [LTP] [PATCH v10 1/8] lib6: Remove runcc.* and the testcases that use it Alexey Kodanev
2015-10-14 8:21 ` [LTP] [PATCH v9 7/8] lib6: Rename Zeng Linggang
2015-10-14 8:21 ` [LTP] [PATCH v9 8/8] ipv6_lib: Add it into default Zeng Linggang
2015-10-08 11:29 ` [LTP] [PATCH v8 3/7] lib6/asapi_04.c: Cleanup Zeng Linggang
2015-10-08 11:29 ` [LTP] [PATCH v8 4/7] lib6/asapi_05.c: Cleanup Zeng Linggang
2015-10-08 11:29 ` [LTP] [PATCH v8 5/7] lib6/asapi_06.c: Cleanup Zeng Linggang
2015-10-08 11:29 ` [LTP] [PATCH v8 6/7] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
2015-10-08 11:29 ` [LTP] [PATCH v8 7/7] ipv6_lib: Add it into default Zeng Linggang
2015-10-07 10:47 ` [LTP] [PATCH v7 3/7] lib6/asapi_04.c: Cleanup Zeng Linggang
2015-10-07 10:47 ` [LTP] [PATCH v7 4/7] lib6/asapi_05.c: Cleanup Zeng Linggang
2015-10-07 10:47 ` [LTP] [PATCH v7 5/7] lib6/asapi_06.c: Cleanup Zeng Linggang
2015-10-07 10:47 ` [LTP] [PATCH v7 6/7] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
2015-10-07 10:47 ` [LTP] [PATCH v7 7/7] ipv6_lib: Add it into default Zeng Linggang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1444804030.4685.6.camel@G08FNSTD140232 \
--to=zenglg.jy@cn.fujitsu.com \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox