[Toybox] [PATCH] Fix `netcat -l -p 12345`.

Josh Gao jmgao at google.com
Wed Jan 2 16:21:12 PST 2019


Previously, when trying to listen on a socket without using one of -4,
-6, or -s, we tried to create an AF_UNSPEC socket, which fails.
---
  toys/net/netcat.c | 4 ++++
  1 file changed, 4 insertions(+)

diff --git a/toys/net/netcat.c b/toys/net/netcat.c
index 761d1f2a..57304f44 100644
--- a/toys/net/netcat.c
+++ b/toys/net/netcat.c
@@ -125,6 +125,10 @@ void netcat_main(void)
        } else {
          size_t bind_addrlen;

+        // If we weren't given an address with which to resolve which  
family to
+        // use, we have to choose.
+        if (family == AF_UNSPEC) family = AF_INET;
+
          address->sa_family = family;

          if (family == AF_INET6) {
-- 
2.20.1.415.g653613c723-goog




More information about the Toybox mailing list