diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/usr.bin/nc/nc.1 | 260 | ||||
| -rw-r--r-- | src/usr.bin/nc/netcat.c | 60 |
2 files changed, 226 insertions, 94 deletions
diff --git a/src/usr.bin/nc/nc.1 b/src/usr.bin/nc/nc.1 index 5bf4480433..64a1dbbc8b 100644 --- a/src/usr.bin/nc/nc.1 +++ b/src/usr.bin/nc/nc.1 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: nc.1,v 1.27 2004/01/22 13:28:46 markus Exp $ | 1 | .\" $OpenBSD: nc.1,v 1.28 2004/02/20 10:53:10 jmc Exp $ |
| 2 | .\" | 2 | .\" |
| 3 | .\" Copyright (c) 1996 David Sacerdote | 3 | .\" Copyright (c) 1996 David Sacerdote |
| 4 | .\" All rights reserved. | 4 | .\" All rights reserved. |
| @@ -30,18 +30,21 @@ | |||
| 30 | .Os | 30 | .Os |
| 31 | .Sh NAME | 31 | .Sh NAME |
| 32 | .Nm nc | 32 | .Nm nc |
| 33 | .Nd "arbitrary TCP and UDP connections and listens" | 33 | .Nd arbitrary TCP and UDP connections and listens |
| 34 | .Sh SYNOPSIS | 34 | .Sh SYNOPSIS |
| 35 | .Nm nc | 35 | .Nm nc |
| 36 | .Op Fl 46hklnrtuvzSU | 36 | .Op Fl 46hklnrStUuvz |
| 37 | .Op Fl i Ar interval | 37 | .Op Fl i Ar interval |
| 38 | .Op Fl p Ar source port | 38 | .Op Fl p Ar source_port |
| 39 | .Op Fl s Ar source ip address | 39 | .Op Fl s Ar source_ip_address |
| 40 | .Op Fl x Ar proxy address Op :port | ||
| 41 | .Op Fl w Ar timeout | 40 | .Op Fl w Ar timeout |
| 42 | .Op Fl X Ar socks version | 41 | .Op Fl X Ar socks_version |
| 42 | .Oo Xo | ||
| 43 | .Fl x Ar proxy_address Ns Oo : Ns | ||
| 44 | .Ar port Oc Oc | ||
| 45 | .Xc | ||
| 43 | .Op Ar hostname | 46 | .Op Ar hostname |
| 44 | .Op Ar port[s] | 47 | .Op Ar port Ns Bq Ar s |
| 45 | .Sh DESCRIPTION | 48 | .Sh DESCRIPTION |
| 46 | The | 49 | The |
| 47 | .Nm | 50 | .Nm |
| @@ -69,7 +72,7 @@ Common uses include: | |||
| 69 | .It | 72 | .It |
| 70 | simple TCP proxies | 73 | simple TCP proxies |
| 71 | .It | 74 | .It |
| 72 | shell\-script based HTTP clients and servers | 75 | shell-script based HTTP clients and servers |
| 73 | .It | 76 | .It |
| 74 | network daemon testing | 77 | network daemon testing |
| 75 | .It | 78 | .It |
| @@ -98,24 +101,41 @@ Forces | |||
| 98 | .Nm | 101 | .Nm |
| 99 | to stay listening for another connection after its current connection | 102 | to stay listening for another connection after its current connection |
| 100 | is completed. | 103 | is completed. |
| 104 | It is an error to use this option without the | ||
| 105 | .Fl l | ||
| 106 | option. | ||
| 101 | .It Fl l | 107 | .It Fl l |
| 102 | Used to specify that | 108 | Used to specify that |
| 103 | .Nm | 109 | .Nm |
| 104 | should listen for an incoming connection rather than initiate a | 110 | should listen for an incoming connection rather than initiate a |
| 105 | connection to a remote host. | 111 | connection to a remote host. |
| 112 | It is an error to use this option in conjunction with the | ||
| 113 | .Fl p , | ||
| 114 | .Fl s , | ||
| 115 | or | ||
| 116 | .Fl z | ||
| 117 | options. | ||
| 106 | .It Fl n | 118 | .It Fl n |
| 107 | Do not do any DNS or service lookups on any specified addresses, | 119 | Do not do any DNS or service lookups on any specified addresses, |
| 108 | hostnames or ports. | 120 | hostnames or ports. |
| 109 | .It Fl p Ar port | 121 | .It Fl p Ar source_port |
| 110 | Specifies the source port | 122 | Specifies the source port |
| 111 | .Nm | 123 | .Nm |
| 112 | should use, subject to privilege restrictions and availability. | 124 | should use, subject to privilege restrictions and availability. |
| 125 | It is an error to use this option in conjunction with the | ||
| 126 | .Fl l | ||
| 127 | option. | ||
| 113 | .It Fl r | 128 | .It Fl r |
| 114 | Specifies that source and/or destination ports should be chosen randomly | 129 | Specifies that source and/or destination ports should be chosen randomly |
| 115 | instead of sequentially within a range or in the order that the system | 130 | instead of sequentially within a range or in the order that the system |
| 116 | assigns them. | 131 | assigns them. |
| 117 | .It Fl s Ar hostname/ip address | 132 | .It Fl S |
| 133 | Enables the RFC 2385 TCP MD5 signature option. | ||
| 134 | .It Fl s Ar source_ip_address | ||
| 118 | Specifies the IP of the interface which is used to send the packets. | 135 | Specifies the IP of the interface which is used to send the packets. |
| 136 | It is an error to use this option in conjunction with the | ||
| 137 | .Fl l | ||
| 138 | option. | ||
| 119 | .It Fl t | 139 | .It Fl t |
| 120 | Causes | 140 | Causes |
| 121 | .Nm | 141 | .Nm |
| @@ -123,6 +143,8 @@ to send RFC 854 DON'T and WON'T responses to RFC 854 DO and WILL requests. | |||
| 123 | This makes it possible to use | 143 | This makes it possible to use |
| 124 | .Nm | 144 | .Nm |
| 125 | to script telnet sessions. | 145 | to script telnet sessions. |
| 146 | .It Fl U | ||
| 147 | Specifies to use Unix Domain Sockets. | ||
| 126 | .It Fl u | 148 | .It Fl u |
| 127 | Use UDP instead of the default option of TCP. | 149 | Use UDP instead of the default option of TCP. |
| 128 | .It Fl v | 150 | .It Fl v |
| @@ -143,72 +165,182 @@ will listen forever for a connection, with or without the | |||
| 143 | .Fl w | 165 | .Fl w |
| 144 | flag. | 166 | flag. |
| 145 | The default is no timeout. | 167 | The default is no timeout. |
| 146 | .It Fl x Ar proxy address Op :port | 168 | .It Fl X Ar socks_version |
| 169 | Requests that | ||
| 170 | .Nm | ||
| 171 | should use the specified version of the SOCKS protocol when talking to | ||
| 172 | a SOCKS proxy. | ||
| 173 | SOCKS versions 4 and 5 are currently supported. | ||
| 174 | If the version is not specified, SOCKS version 5 is used. | ||
| 175 | .It Xo | ||
| 176 | .Fl x Ar proxy_address Ns Oo : Ns | ||
| 177 | .Ar port Oc | ||
| 178 | .Xc | ||
| 147 | Requests that | 179 | Requests that |
| 148 | .Nm | 180 | .Nm |
| 149 | should connect to | 181 | should connect to |
| 150 | .Ar hostname | 182 | .Ar hostname |
| 151 | using a SOCKS proxy at address and port. | 183 | using a SOCKS proxy at |
| 152 | If port is not specified, port 1080 is used. | 184 | .Ar proxy_address |
| 185 | and | ||
| 186 | .Ar port . | ||
| 187 | If | ||
| 188 | .Ar port | ||
| 189 | is not specified, port 1080 is used. | ||
| 153 | .It Fl z | 190 | .It Fl z |
| 154 | Specifies that | 191 | Specifies that |
| 155 | .Nm | 192 | .Nm |
| 156 | should just scan for listening daemons, without sending any data to them. | 193 | should just scan for listening daemons, without sending any data to them. |
| 157 | .It Fl S | 194 | It is an error to use this option in conjunction with the |
| 158 | Enables the RFC 2385 TCP MD5 signature option. | 195 | .Fl l |
| 159 | .It Fl U | 196 | option. |
| 160 | Specifies to use Unix Domain Sockets. | ||
| 161 | .It Fl X Ar version | ||
| 162 | Requests that | ||
| 163 | .Nm | ||
| 164 | should use the specified version of the SOCKS protocol when talking to | ||
| 165 | a SOCKS proxy. | ||
| 166 | If version is not specified, SOCKS version 5 is used. | ||
| 167 | .El | 197 | .El |
| 198 | .Sh CLIENT/SERVER MODEL | ||
| 199 | It is quite simple to build a very basic client/server model using | ||
| 200 | .Nm . | ||
| 201 | On one console, start | ||
| 202 | .Nm | ||
| 203 | listening on a specific port for a connection. | ||
| 204 | For example: | ||
| 205 | .Pp | ||
| 206 | .Dl $ nc -l 1234 | ||
| 207 | .Pp | ||
| 208 | .Nm | ||
| 209 | is now listening on port 1234 for a connection. | ||
| 210 | On a second console | ||
| 211 | .Pq or a second machine , | ||
| 212 | connect to the machine and port being listened on: | ||
| 213 | .Pp | ||
| 214 | .Dl $ nc 127.0.0.1 1234 | ||
| 215 | .Pp | ||
| 216 | There should now be a connection between the ports. | ||
| 217 | Anything typed at the second console will be concatenated to the first, | ||
| 218 | and vice-versa. | ||
| 219 | After the connection has been set up, | ||
| 220 | .Nm | ||
| 221 | does not really care which side is being used as a | ||
| 222 | .Sq server | ||
| 223 | and which side is being used as a | ||
| 224 | .Sq client . | ||
| 225 | The connection may be terminated using an | ||
| 226 | .Dv EOF | ||
| 227 | .Pq Sq ^D . | ||
| 228 | .Sh DATA TRANSFER | ||
| 229 | The example in the previous section can be expanded to build a | ||
| 230 | basic data transfer model. | ||
| 231 | Any information input into one end of the connection will be output | ||
| 232 | to the other end, and input and output can be easily captured in order to | ||
| 233 | emulate file transfer. | ||
| 234 | .Pp | ||
| 235 | Start by using | ||
| 236 | .Nm | ||
| 237 | to listen on a specific port, with output captured into a file: | ||
| 238 | .Pp | ||
| 239 | .Dl $ nc -l 1234 \*(Gt filename.out | ||
| 240 | .Pp | ||
| 241 | Using a second machine, connect to the listening | ||
| 242 | .Nm | ||
| 243 | process, feeding it the file which is to be transferred: | ||
| 244 | .Pp | ||
| 245 | .Dl $ nc host.example.com 1234 \*(Lt filename.in | ||
| 246 | .Pp | ||
| 247 | After the file has been transferred, the connection will close automatically. | ||
| 248 | .Sh TALKING TO SERVERS | ||
| 249 | It is sometimes useful to talk to servers | ||
| 250 | .Dq by hand | ||
| 251 | rather than through a user interface. | ||
| 252 | It can aid in troubleshooting, | ||
| 253 | when it might be necessary to verify what data a server is sending | ||
| 254 | in response to commands issued by the client. | ||
| 255 | For example, to retrieve the home page of a web site: | ||
| 256 | .Pp | ||
| 257 | .Dl $ echo \&"GET\&" | nc host.example.com 80 | ||
| 258 | .Pp | ||
| 259 | Note that this also displays the headers sent by the web server. | ||
| 260 | They can be filtered, using a tool such as | ||
| 261 | .Xr sed 1 , | ||
| 262 | if necessary. | ||
| 263 | .Pp | ||
| 264 | More complicated examples can be built up when the user knows the format | ||
| 265 | of requests required by the server. | ||
| 266 | As another example, an email may be submitted to an SMTP server using: | ||
| 267 | .Bd -literal -offset indent | ||
| 268 | $ nc localhost 25 \*(Lt\*(Lt EOF | ||
| 269 | HELO host.example.com | ||
| 270 | MAIL FROM: \*(Ltuser@host.example.com\*(Gt | ||
| 271 | RCPT TO: \*(Ltuser2@host.example.com\*(Gt | ||
| 272 | DATA | ||
| 273 | Body of email. | ||
| 274 | \&. | ||
| 275 | QUIT | ||
| 276 | EOF | ||
| 277 | .Ed | ||
| 278 | .Sh PORT SCANNING | ||
| 279 | It may be useful to know which ports are open and running services on | ||
| 280 | a target machine. | ||
| 281 | The | ||
| 282 | .Fl z | ||
| 283 | flag can be used to tell | ||
| 284 | .Nm | ||
| 285 | not to initiate a connection, | ||
| 286 | together with the | ||
| 287 | .Fl v | ||
| 288 | .Pq verbose | ||
| 289 | flag, | ||
| 290 | to report open ports. | ||
| 291 | For example: | ||
| 292 | .Bd -literal -offset indent | ||
| 293 | $ nc -vz host.example.com 20-30 | ||
| 294 | Connection to host.example.com 22 port [tcp/ssh] succeeded! | ||
| 295 | Connection to host.example.com 25 port [tcp/smtp] succeeded! | ||
| 296 | .Ed | ||
| 297 | .Pp | ||
| 298 | The port range was specified to limit the search to ports 20 \- 30. | ||
| 299 | .Pp | ||
| 300 | Alternatively, it might be useful to know which server software | ||
| 301 | is running, and which versions. | ||
| 302 | This information is often contained within the greeting banners. | ||
| 303 | In order to retrieve these, it is necessary to first make a connection, | ||
| 304 | and then break the connection when the banner has been retrieved. | ||
| 305 | This can be accomplished by specifying a small timeout with the | ||
| 306 | .Fl w | ||
| 307 | flag, or perhaps by issuing a | ||
| 308 | .Qq Dv QUIT | ||
| 309 | command to the server: | ||
| 310 | .Bd -literal -offset indent | ||
| 311 | $ echo "QUIT" | nc host.example.com 20-30 | ||
| 312 | SSH-1.99-OpenSSH_3.6.1p2 | ||
| 313 | Protocol mismatch. | ||
| 314 | 220 host.example.com IMS SMTP Receiver Version 0.84 Ready | ||
| 315 | .Ed | ||
| 168 | .Sh EXAMPLES | 316 | .Sh EXAMPLES |
| 169 | .Bl -tag -width x | 317 | Open a TCP connection to port 42 of hostname, using port 31337 as |
| 170 | .It Li "$ nc hostname 42" | 318 | the source port, with a timeout of 5 seconds: |
| 171 | Open a TCP connection to port 42 of hostname. | 319 | .Pp |
| 172 | .It Li "$ nc -p 31337 hostname 42" | 320 | .Dl $ nc -p 31337 -w 5 hostname 42 |
| 173 | Open a TCP connection to port 42 of hostname, and use port 31337 as | 321 | .Pp |
| 174 | the source port. | 322 | Open a UDP connection to port 53 of hostname: |
| 175 | .It Li "$ nc -w 5 hostname 42" | 323 | .Pp |
| 176 | Open a TCP connection to port 42 of hostname, and timeout after | 324 | .Dl $ nc -u hostname 53 |
| 177 | five seconds while attempting to connect. | 325 | .Pp |
| 178 | .It Li "$ nc -u hostname 53" | ||
| 179 | Open a UDP connection to port 53 of hostname. | ||
| 180 | .It Li "$ nc -s 10.1.2.3 example.host 42" | ||
| 181 | Open a TCP connection to port 42 of example.host using 10.1.2.3 as the | 326 | Open a TCP connection to port 42 of example.host using 10.1.2.3 as the |
| 182 | IP for the local end of the connection. | 327 | IP for the local end of the connection: |
| 183 | .It Li "$ nc -v hostname 42" | 328 | .Pp |
| 184 | Open a TCP connection to port 42 of hostname, displaying some | 329 | .Dl $ nc -s 10.1.2.3 example.host 42 |
| 185 | diagnostic messages on stderr. | 330 | .Pp |
| 186 | .It Li "$ nc -v -z hostname 20-30" | ||
| 187 | Attempt to open TCP connections to ports 20 through 30 of | ||
| 188 | hostname, and report which ones | ||
| 189 | .Nm | ||
| 190 | was able to connect to. | ||
| 191 | .It Li "$ nc -v -u -z -w 3 hostname 20-30" | ||
| 192 | Send UDP packets to ports 20-30 of example.host, and report which ones | 331 | Send UDP packets to ports 20-30 of example.host, and report which ones |
| 193 | did not respond with an ICMP packet after three seconds. | 332 | responded with an ICMP packet after three seconds: |
| 194 | .It Li "$ nc -l 3000" | 333 | .Pp |
| 195 | Listen on TCP port 3000, and once there is a connection, send stdin to | 334 | .Dl $ nc -uvz -w 3 hostname 20-30 |
| 196 | the remote host, and send data from the remote host to stdout. | 335 | .Pp |
| 197 | .It Li "$ echo foobar | nc hostname 1000" | 336 | Create and listen on a Unix Domain Socket: |
| 198 | Connect to port 1000 of hostname, send the string "foobar" | 337 | .Pp |
| 199 | followed by a newline, and move data from port 1000 of hostname to | 338 | .Dl $ nc -lU /var/tmp/dsocket |
| 200 | stdout until hostname closes the connection. | ||
| 201 | .It Li "$ nc -U /var/tmp/dsocket" | ||
| 202 | Connect to a Unix Domain Socket. | ||
| 203 | .It Li "$ nc -lU /var/tmp/dsocket" | ||
| 204 | Create and listen on a Unix Domain Socket. | ||
| 205 | .El | ||
| 206 | .Sh SEE ALSO | 339 | .Sh SEE ALSO |
| 207 | .Xr cat 1 , | 340 | .Xr cat 1 |
| 208 | .Xr telnet 1 | ||
| 209 | .Sh AUTHORS | 341 | .Sh AUTHORS |
| 210 | Original implementation by *Hobbit* | 342 | Original implementation by *Hobbit* |
| 211 | .Aq hobbit@avian.org . | 343 | .Aq hobbit@avian.org . |
| 212 | .Pp | 344 | .br |
| 213 | Rewritten with IPv6 support by Eric Jackson | 345 | Rewritten with IPv6 support by |
| 214 | .Aq ericj@monkey.org . | 346 | .An Eric Jackson Aq ericj@monkey.org . |
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index beca89e01c..505cbd77b1 100644 --- a/src/usr.bin/nc/netcat.c +++ b/src/usr.bin/nc/netcat.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: netcat.c,v 1.66 2004/01/31 21:09:15 henning Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.67 2004/02/20 10:53:10 jmc Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> | 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> |
| 4 | * | 4 | * |
| @@ -63,7 +63,7 @@ | |||
| 63 | int iflag; /* Interval Flag */ | 63 | int iflag; /* Interval Flag */ |
| 64 | int kflag; /* More than one connect */ | 64 | int kflag; /* More than one connect */ |
| 65 | int lflag; /* Bind to local port */ | 65 | int lflag; /* Bind to local port */ |
| 66 | int nflag; /* Dont do name lookup */ | 66 | int nflag; /* Don't do name look up */ |
| 67 | char *pflag; /* Localport flag */ | 67 | char *pflag; /* Localport flag */ |
| 68 | int rflag; /* Random ports flag */ | 68 | int rflag; /* Random ports flag */ |
| 69 | char *sflag; /* Source Address */ | 69 | char *sflag; /* Source Address */ |
| @@ -216,7 +216,7 @@ main(int argc, char *argv[]) | |||
| 216 | if (!lflag && kflag) | 216 | if (!lflag && kflag) |
| 217 | errx(1, "must use -l with -k"); | 217 | errx(1, "must use -l with -k"); |
| 218 | 218 | ||
| 219 | /* Initialize addrinfo structure */ | 219 | /* Initialize addrinfo structure. */ |
| 220 | if (family != AF_UNIX) { | 220 | if (family != AF_UNIX) { |
| 221 | memset(&hints, 0, sizeof(struct addrinfo)); | 221 | memset(&hints, 0, sizeof(struct addrinfo)); |
| 222 | hints.ai_family = family; | 222 | hints.ai_family = family; |
| @@ -261,7 +261,7 @@ main(int argc, char *argv[]) | |||
| 261 | if (family == AF_UNIX) | 261 | if (family == AF_UNIX) |
| 262 | s = unix_listen(host); | 262 | s = unix_listen(host); |
| 263 | 263 | ||
| 264 | /* Allow only one connection at a time, but stay alive */ | 264 | /* Allow only one connection at a time, but stay alive. */ |
| 265 | for (;;) { | 265 | for (;;) { |
| 266 | if (family != AF_UNIX) | 266 | if (family != AF_UNIX) |
| 267 | s = local_listen(host, uport, hints); | 267 | s = local_listen(host, uport, hints); |
| @@ -315,10 +315,10 @@ main(int argc, char *argv[]) | |||
| 315 | } else { | 315 | } else { |
| 316 | int i = 0; | 316 | int i = 0; |
| 317 | 317 | ||
| 318 | /* construct the portlist[] array */ | 318 | /* Construct the portlist[] array. */ |
| 319 | build_ports(uport); | 319 | build_ports(uport); |
| 320 | 320 | ||
| 321 | /* Cycle through portlist, connecting to each port */ | 321 | /* Cycle through portlist, connecting to each port. */ |
| 322 | for (i = 0; portlist[i] != NULL; i++) { | 322 | for (i = 0; portlist[i] != NULL; i++) { |
| 323 | if (s) | 323 | if (s) |
| 324 | close(s); | 324 | close(s); |
| @@ -334,7 +334,7 @@ main(int argc, char *argv[]) | |||
| 334 | 334 | ||
| 335 | ret = 0; | 335 | ret = 0; |
| 336 | if (vflag || zflag) { | 336 | if (vflag || zflag) { |
| 337 | /* For UDP, make sure we are connected */ | 337 | /* For UDP, make sure we are connected. */ |
| 338 | if (uflag) { | 338 | if (uflag) { |
| 339 | if (udptest(s) == -1) { | 339 | if (udptest(s) == -1) { |
| 340 | ret = 1; | 340 | ret = 1; |
| @@ -342,7 +342,7 @@ main(int argc, char *argv[]) | |||
| 342 | } | 342 | } |
| 343 | } | 343 | } |
| 344 | 344 | ||
| 345 | /* Don't lookup port if -n */ | 345 | /* Don't look up port if -n. */ |
| 346 | if (nflag) | 346 | if (nflag) |
| 347 | sv = NULL; | 347 | sv = NULL; |
| 348 | else { | 348 | else { |
| @@ -368,7 +368,7 @@ main(int argc, char *argv[]) | |||
| 368 | 368 | ||
| 369 | /* | 369 | /* |
| 370 | * unix_connect() | 370 | * unix_connect() |
| 371 | * Return's a socket connected to a local unix socket. Return's -1 on failure. | 371 | * Returns a socket connected to a local unix socket. Returns -1 on failure. |
| 372 | */ | 372 | */ |
| 373 | int | 373 | int |
| 374 | unix_connect(char *path) | 374 | unix_connect(char *path) |
| @@ -399,7 +399,7 @@ unix_connect(char *path) | |||
| 399 | 399 | ||
| 400 | /* | 400 | /* |
| 401 | * unix_listen() | 401 | * unix_listen() |
| 402 | * create a unix domain socket, and listen on it. | 402 | * Create a unix domain socket, and listen on it. |
| 403 | */ | 403 | */ |
| 404 | int | 404 | int |
| 405 | unix_listen(char *path) | 405 | unix_listen(char *path) |
| @@ -407,7 +407,7 @@ unix_listen(char *path) | |||
| 407 | struct sockaddr_un sun; | 407 | struct sockaddr_un sun; |
| 408 | int s; | 408 | int s; |
| 409 | 409 | ||
| 410 | /* create unix domain socket */ | 410 | /* Create unix domain socket. */ |
| 411 | if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) | 411 | if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) |
| 412 | return (-1); | 412 | return (-1); |
| 413 | 413 | ||
| @@ -435,8 +435,8 @@ unix_listen(char *path) | |||
| 435 | 435 | ||
| 436 | /* | 436 | /* |
| 437 | * remote_connect() | 437 | * remote_connect() |
| 438 | * Return's a socket connected to a remote host. Properly bind's to a local | 438 | * Returns a socket connected to a remote host. Properly binds to a local |
| 439 | * port or source address if needed. Return's -1 on failure. | 439 | * port or source address if needed. Returns -1 on failure. |
| 440 | */ | 440 | */ |
| 441 | int | 441 | int |
| 442 | remote_connect(char *host, char *port, struct addrinfo hints) | 442 | remote_connect(char *host, char *port, struct addrinfo hints) |
| @@ -453,7 +453,7 @@ remote_connect(char *host, char *port, struct addrinfo hints) | |||
| 453 | res0->ai_protocol)) < 0) | 453 | res0->ai_protocol)) < 0) |
| 454 | continue; | 454 | continue; |
| 455 | 455 | ||
| 456 | /* Bind to a local port or source address if specified */ | 456 | /* Bind to a local port or source address if specified. */ |
| 457 | if (sflag || pflag) { | 457 | if (sflag || pflag) { |
| 458 | struct addrinfo ahints, *ares; | 458 | struct addrinfo ahints, *ares; |
| 459 | 459 | ||
| @@ -497,8 +497,8 @@ remote_connect(char *host, char *port, struct addrinfo hints) | |||
| 497 | 497 | ||
| 498 | /* | 498 | /* |
| 499 | * local_listen() | 499 | * local_listen() |
| 500 | * Return's a socket listening on a local port, binds to specified source | 500 | * Returns a socket listening on a local port, binds to specified source |
| 501 | * address. Return's -1 on failure. | 501 | * address. Returns -1 on failure. |
| 502 | */ | 502 | */ |
| 503 | int | 503 | int |
| 504 | local_listen(char *host, char *port, struct addrinfo hints) | 504 | local_listen(char *host, char *port, struct addrinfo hints) |
| @@ -507,7 +507,7 @@ local_listen(char *host, char *port, struct addrinfo hints) | |||
| 507 | int s, ret, x = 1; | 507 | int s, ret, x = 1; |
| 508 | int error; | 508 | int error; |
| 509 | 509 | ||
| 510 | /* Allow nodename to be null */ | 510 | /* Allow nodename to be null. */ |
| 511 | hints.ai_flags |= AI_PASSIVE; | 511 | hints.ai_flags |= AI_PASSIVE; |
| 512 | 512 | ||
| 513 | /* | 513 | /* |
| @@ -570,7 +570,7 @@ readwrite(int nfd) | |||
| 570 | pfd[0].fd = nfd; | 570 | pfd[0].fd = nfd; |
| 571 | pfd[0].events = POLLIN; | 571 | pfd[0].events = POLLIN; |
| 572 | 572 | ||
| 573 | /* Setup STDIN FD */ | 573 | /* Set up STDIN FD. */ |
| 574 | pfd[1].fd = wfd; | 574 | pfd[1].fd = wfd; |
| 575 | pfd[1].events = POLLIN; | 575 | pfd[1].events = POLLIN; |
| 576 | 576 | ||
| @@ -620,7 +620,7 @@ readwrite(int nfd) | |||
| 620 | } | 620 | } |
| 621 | } | 621 | } |
| 622 | 622 | ||
| 623 | /* Deal with RFC854 WILL/WONT DO/DONT negotiation */ | 623 | /* Deal with RFC 854 WILL/WONT DO/DONT negotiation. */ |
| 624 | void | 624 | void |
| 625 | atelnet(int nfd, unsigned char *buf, unsigned int size) | 625 | atelnet(int nfd, unsigned char *buf, unsigned int size) |
| 626 | { | 626 | { |
| @@ -657,7 +657,7 @@ atelnet(int nfd, unsigned char *buf, unsigned int size) | |||
| 657 | /* | 657 | /* |
| 658 | * build_ports() | 658 | * build_ports() |
| 659 | * Build an array or ports in portlist[], listing each port | 659 | * Build an array or ports in portlist[], listing each port |
| 660 | * that we should try to connect too. | 660 | * that we should try to connect to. |
| 661 | */ | 661 | */ |
| 662 | void | 662 | void |
| 663 | build_ports(char *p) | 663 | build_ports(char *p) |
| @@ -673,7 +673,7 @@ build_ports(char *p) | |||
| 673 | *n = '\0'; | 673 | *n = '\0'; |
| 674 | n++; | 674 | n++; |
| 675 | 675 | ||
| 676 | /* Make sure the ports are in order: lowest->highest */ | 676 | /* Make sure the ports are in order: lowest->highest. */ |
| 677 | hi = (int)strtoul(n, &endp, 10); | 677 | hi = (int)strtoul(n, &endp, 10); |
| 678 | if (hi <= 0 || hi > PORT_MAX || *endp != '\0') | 678 | if (hi <= 0 || hi > PORT_MAX || *endp != '\0') |
| 679 | errx(1, "port range not valid"); | 679 | errx(1, "port range not valid"); |
| @@ -687,7 +687,7 @@ build_ports(char *p) | |||
| 687 | lo = cp; | 687 | lo = cp; |
| 688 | } | 688 | } |
| 689 | 689 | ||
| 690 | /* Load ports sequentially */ | 690 | /* Load ports sequentially. */ |
| 691 | for (cp = lo; cp <= hi; cp++) { | 691 | for (cp = lo; cp <= hi; cp++) { |
| 692 | portlist[x] = calloc(1, PORT_MAX_LEN); | 692 | portlist[x] = calloc(1, PORT_MAX_LEN); |
| 693 | if (portlist[x] == NULL) | 693 | if (portlist[x] == NULL) |
| @@ -696,7 +696,7 @@ build_ports(char *p) | |||
| 696 | x++; | 696 | x++; |
| 697 | } | 697 | } |
| 698 | 698 | ||
| 699 | /* Randomly swap ports */ | 699 | /* Randomly swap ports. */ |
| 700 | if (rflag) { | 700 | if (rflag) { |
| 701 | int y; | 701 | int y; |
| 702 | char *c; | 702 | char *c; |
| @@ -722,7 +722,7 @@ build_ports(char *p) | |||
| 722 | /* | 722 | /* |
| 723 | * udptest() | 723 | * udptest() |
| 724 | * Do a few writes to see if the UDP port is there. | 724 | * Do a few writes to see if the UDP port is there. |
| 725 | * XXX - Better way of doing this? Doesn't work for IPv6 | 725 | * XXX - Better way of doing this? Doesn't work for IPv6. |
| 726 | * Also fails after around 100 ports checked. | 726 | * Also fails after around 100 ports checked. |
| 727 | */ | 727 | */ |
| 728 | int | 728 | int |
| @@ -746,9 +746,6 @@ help(void) | |||
| 746 | fprintf(stderr, "\tCommand Summary:\n\ | 746 | fprintf(stderr, "\tCommand Summary:\n\ |
| 747 | \t-4 Use IPv4\n\ | 747 | \t-4 Use IPv4\n\ |
| 748 | \t-6 Use IPv6\n\ | 748 | \t-6 Use IPv6\n\ |
| 749 | \t-S Enable the TCP MD5 signature option\n\ | ||
| 750 | \t-U Use UNIX domain socket\n\ | ||
| 751 | \t-X vers\t SOCKS version (4 or 5)\n\ | ||
| 752 | \t-h This help text\n\ | 749 | \t-h This help text\n\ |
| 753 | \t-i secs\t Delay interval for lines sent, ports scanned\n\ | 750 | \t-i secs\t Delay interval for lines sent, ports scanned\n\ |
| 754 | \t-k Keep inbound sockets open for multiple connects\n\ | 751 | \t-k Keep inbound sockets open for multiple connects\n\ |
| @@ -756,11 +753,14 @@ help(void) | |||
| 756 | \t-n Suppress name/port resolutions\n\ | 753 | \t-n Suppress name/port resolutions\n\ |
| 757 | \t-p port\t Specify local port for remote connects\n\ | 754 | \t-p port\t Specify local port for remote connects\n\ |
| 758 | \t-r Randomize remote ports\n\ | 755 | \t-r Randomize remote ports\n\ |
| 756 | \t-S Enable the TCP MD5 signature option\n\ | ||
| 759 | \t-s addr\t Local source address\n\ | 757 | \t-s addr\t Local source address\n\ |
| 760 | \t-t Answer TELNET negotiation\n\ | 758 | \t-t Answer TELNET negotiation\n\ |
| 759 | \t-U Use UNIX domain socket\n\ | ||
| 761 | \t-u UDP mode\n\ | 760 | \t-u UDP mode\n\ |
| 762 | \t-v Verbose\n\ | 761 | \t-v Verbose\n\ |
| 763 | \t-w secs\t Timeout for connects and final net reads\n\ | 762 | \t-w secs\t Timeout for connects and final net reads\n\ |
| 763 | \t-X vers\t SOCKS version (4 or 5)\n\ | ||
| 764 | \t-x addr[:port]\tSpecify socks proxy address and port\n\ | 764 | \t-x addr[:port]\tSpecify socks proxy address and port\n\ |
| 765 | \t-z Zero-I/O mode [used for scanning]\n\ | 765 | \t-z Zero-I/O mode [used for scanning]\n\ |
| 766 | Port numbers can be individual or ranges: lo-hi [inclusive]\n"); | 766 | Port numbers can be individual or ranges: lo-hi [inclusive]\n"); |
| @@ -770,9 +770,9 @@ help(void) | |||
| 770 | void | 770 | void |
| 771 | usage(int ret) | 771 | usage(int ret) |
| 772 | { | 772 | { |
| 773 | fprintf(stderr, "usage: nc [-46SUhklnrtuvz] [-i interval] [-p source port]\n"); | 773 | fprintf(stderr, "usage: nc [-46hklnrStUuvz] [-i interval] [-p source_port] [-s source_ip_address]\n"); |
| 774 | fprintf(stderr, "\t [-s ip address] [-w timeout] [-X vers] [-x proxy address [:port]]\n"); | 774 | fprintf(stderr, "\t [-w timeout] [-X socks_version] [-x proxy_address[:port]] [hostname]\n"); |
| 775 | fprintf(stderr, "\t [hostname] [port[s...]]\n"); | 775 | fprintf(stderr, "\t [port[s]]\n"); |
| 776 | if (ret) | 776 | if (ret) |
| 777 | exit(1); | 777 | exit(1); |
| 778 | } | 778 | } |
