<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<pre style="color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; overflow-wrap: break-word; white-space: pre-wrap;">Signed-off-by: Ramon Pantin <a class="moz-txt-link-rfc2396E" href="mailto:pantin@google.com"><pantin@google.com></a>
---
include/safe_net_fn.h | 3 +++
include/tst_safe_net.h | 3 +++
lib/safe_net.c | 28 ++++++++++++++++++++++++++++
3 files changed, 34 insertions(+)
diff --git a/include/safe_net_fn.h b/include/safe_net_fn.h
index 89e5bf0cc..3183b2a1c 100644
--- a/include/safe_net_fn.h
+++ b/include/safe_net_fn.h
@@ -33,6 +33,9 @@ int tst_getsockport(const char *file, const int lineno, int sockfd);
int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void),
int domain, int type, int protocol);
+int safe_socketpair(const char *file, const int lineno, int domain, int type,
+ int protocol, int sv[]);
+
int safe_getsockopt(const char *file, const int lineno, int sockfd, int level,
int optname, void *optval, socklen_t *optlen);
diff --git a/include/tst_safe_net.h b/include/tst_safe_net.h
index d0c0a1dc5..83a2f27bf 100644
--- a/include/tst_safe_net.h
+++ b/include/tst_safe_net.h
@@ -32,6 +32,9 @@
#define SAFE_SOCKET(domain, type, protocol) \
safe_socket(__FILE__, __LINE__, NULL, domain, type, protocol)
+#define SAFE_SOCKETPAIR(domain, type, protocol, sv) \
+ safe_socketpair(__FILE__, __LINE__, domain, type, protocol, sv)
+
#define SAFE_GETSOCKOPT(fd, level, optname, optval, optlen) \
safe_getsockopt(__FILE__, __LINE__, fd, level, optname, optval, optlen)
diff --git a/lib/safe_net.c b/lib/safe_net.c
index 64e2cbcf6..4ab6ae48e 100644
--- a/lib/safe_net.c
+++ b/lib/safe_net.c
@@ -132,6 +132,34 @@ int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void),
return rval;
}
+int safe_socketpair(const char *file, const int lineno, int domain, int type,
+ int protocol, int sv[])
+{
+ int rval, ttype;
+
+ rval = socketpair(domain, type, protocol, sv);
+
+ if (rval < 0) {
+ switch (errno) {
+ case EPROTONOSUPPORT:
+ case ESOCKTNOSUPPORT:
+ case EOPNOTSUPP:
+ case EPFNOSUPPORT:
+ case EAFNOSUPPORT:
+ ttype = TCONF;
+ break;
+ default:
+ ttype = TBROK;
+ }
+
+ tst_brkm(ttype | TERRNO, NULL,
+ "%s:%d: socketpair(%d, %d, %d, %p) failed",
+ file, lineno, domain, type, protocol, sv);
+ }
+
+ return rval;
+}
+
int safe_getsockopt(const char *file, const int lineno, int sockfd, int level,
int optname, void *optval, socklen_t *optlen)
{
--
2.20.0.rc2.403.gdbc3b29805-goog
</pre>
<br class="Apple-interchange-newline">
</body>
</html>