Hi bluhm,

Very sorry for my remiss! Updated, thanks!

Index: netcat.c
===================================================================
RCS file: /cvs/src/usr.bin/nc/netcat.c,v
retrieving revision 1.192
diff -u -p -r1.192 netcat.c
--- netcat.c    10 Aug 2018 17:15:22 -0000      1.192
+++ netcat.c    6 Sep 2018 10:10:07 -0000
@@ -564,8 +564,11 @@ main(int argc, char *argv[])
                }
                /* Allow only one connection at a time, but stay alive. */
                for (;;) {
-                       if (family != AF_UNIX)
+                       if (family != AF_UNIX) {
+                               if (s != -1)
+                                       close(s);
                                s = local_listen(host, uport, hints);
+                       }
                        if (s < 0)
                                err(1, NULL);
                        if (uflag && kflag) {
@@ -622,9 +625,7 @@ main(int argc, char *argv[])
                                }
                                close(connfd);
                        }
-                       if (family != AF_UNIX)
-                               close(s);
-                       else if (uflag) {
+                       if (family == AF_UNIX && uflag) {
                                if (connect(s, NULL, 0) < 0)
                                        err(1, "connect");
                        }


On 9/6/2018 8:53 PM, Alexander Bluhm wrote:
> On Thu, Sep 06, 2018 at 06:27:15PM +0800, Nan Xiao wrote:
>> @@ -564,8 +564,11 @@ main(int argc, char *argv[])
>>              }
>>              /* Allow only one connection at a time, but stay alive. */
>>              for (;;) {
>> -                    if (family != AF_UNIX)
>> +                    if (family != AF_UNIX) {
>> +                            if (s == -1)
> 
> This has to be (s != -1).
> 
>> +                                    close(s);
>>                              s = local_listen(host, uport, hints);
>> +                    }
>>                      if (s < 0)
>>                              err(1, NULL);
>>                      if (uflag && kflag) {
>> @@ -622,9 +625,7 @@ main(int argc, char *argv[])
>>                              }
>>                              close(connfd);
>>                      }
>> -                    if (family != AF_UNIX)
>> -                            close(s);
>> -                    else if (uflag) {
>> +                    if (family == AF_UNIX && uflag) {
>>                              if (connect(s, NULL, 0) < 0)
>>                                      err(1, "connect");
>>                      }
> 
> otherwise OK bluhm@
> 

-- 
Best Regards
Nan Xiao(肖楠)

Reply via email to