Menu

#37 -lp doesn't not act like original

open
5
2014-08-21
2007-07-30
Anonymous
No

Fedora 7
The original netcat allows this:

nc -lvnp 31000 127.0.0.1 > x

The man page says this should work:

SYNOPSIS
netcat [options] hostname port [port] ...

netcat -l -p port [options] [hostname] [port] ...

However, GNU netcat does this:
$ nc -lvnp 31000 127.0.0.1 > x
nc: cannot use -p and -l

Discussion

  • Denis Vlasenko

    Denis Vlasenko - 2009-03-18

    I second that.

    GNU nc broke command-line compatibility with original nc-1.10 needlessly.
    This causes PITA for anyone trying to use nc -l from scripts.

    With -l, local port used to be specified with -p:

    nc-1.10:
    # ./nc -vvv -l -p 1111
    listening on [any] 1111 ...

    Not in GNU nc:
    # nc -vvv -l -p 1111
    usage: nc [-46DdhklnrStUuvzC] [-i interval] [-p source_port]
    [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_version]
    [-x proxy_address[:port]] [hostname] [port[s]]

    GNU nc requires it to be specified like this:
    # nc -vvv -l 0.0.0.0 1111
    (waits for connections)

    [Note that the second buglet is here - despite -vvv nothing like "listening on [any] 1111 ..." is printed]

    This format (nc -vvv -l 0.0.0.0 1111) was accepted by original nc,
    but had completely different meaning! It meant "listen on random port
    (because -p NNN is missing), and accept only connections from
    0.0.0.0 1111":

    # ./nc -vvv -l 0.0.0.0 1111
    0.0.0.0: inverse host lookup failed:
    listening on [any] 46000 ...

    Original's interpretation of parameters is more consistent:

    nc ... [-l] [-s LOCAL_IP] [p LOCAL_PORT] [REMOTE_IP] [REMOTE_PORT]

    whereas GNU nc has something like

    nc ... -l LOCAL_IP LOCAL_PORT
    or
    nc ... -l REMOTE_IP REMOTE_PORT

    Help text isn't too obvious about it:
    # nc
    usage: nc [-46DdhklnrStUuvzC] [-i interval] [-p source_port]
    [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_version]
    [-x proxy_address[:port]] [hostname] [port[s]]

     
  • Denis Vlasenko

    Denis Vlasenko - 2009-03-18

    In previous comment, I meant:

    nc ... -l LOCAL_IP LOCAL_PORT
    or
    nc ... REMOTE_IP REMOTE_PORT

     
  • Giovanni Giacobbi

    I'll investigate this problem.

     
  • Giovanni Giacobbi

    • assigned_to: nobody --> themnemonic
     

Log in to post a comment.