LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-24-2007, 01:18 PM   #1
-kc-
LQ Newbie
 
Registered: Jun 2007
Distribution: Slackware
Posts: 21

Rep: Reputation: 15
netcat -q option doesn't work


netcat -q option either doesn't work for me or I got it wrong:
from man 1:
-q seconds after EOF is detected, wait the specified number of seconds and then quit.
Code:
$ nc -lp 9999 <bigfile &
$ nc localhost 9999 -q seconds </dev/null
Both exit in a fraction of second, and I get always the same (small) amount of bigfile on the client side, no matter what number of seconds I use.
What does that number mean? Shouldn't it have the same effect as this one?
Code:
$ nc -lp 9999 <bigfile &
$ sleep seconds | nc localhost 9999 -q 0
This is for version 1.10-21 and 1.10-33 on Slackware 10.2.
GNU and OpenBSD netcat as well as the original nc 1.10, don't have a -q option.

thanks
kc
 
Old 06-24-2007, 08:00 PM   #2
namit
Member
 
Registered: Aug 2005
Distribution: Debian
Posts: 355

Rep: Reputation: 30
is this not a -Q ?
 
Old 06-25-2007, 04:32 PM   #3
-kc-
LQ Newbie
 
Registered: Jun 2007
Distribution: Slackware
Posts: 21

Original Poster
Rep: Reputation: 15
I'm afraid not:
nc: invalid option -- Q
nc -h for help


Anyone know who's the maintainer of the patch for the -q option? Slackware and Debian distribute the patched version. Here's some code from the patch:
Code:
int o_quit = -1; /* 0 == quit-now; >0 == quit after o_quit seconds */
[...]
/* quit :
   handler for a "-q" timeout (exit 0 instead of 1) */
void quit()
{
  close(netfd);
  exit(0);
}
[...]
/* if the user asked to exit on EOF, do it */
if (o_quit == 0) {
  shutdown(netfd, 1);
  close (fd);
  exit (0);
}
/* if user asked to die after a while, arrange for it */
if (o_quit > 0) {
  shutdown(netfd, 1);
  signal (SIGALRM, quit);
  alarm(o_quit);
}
[...]
case 'q':				/* quit after stdin does EOF */
 o_quit = atoi(optarg); break;
thanks
kc
 
Old 06-25-2007, 04:50 PM   #4
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
http://packages.debian.org/changelog...0-33/changelog

From the code it looks like when EOF is reached,
if -q is given, close quickly the socket (shutdown method)
then wait for the time given and close cleanly the socket (close method)

Never saw this option!
 
Old 06-26-2007, 10:33 AM   #5
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
I tried it and as you said, it doesn't change anything.
Quite obscure option.
 
Old 06-30-2007, 08:44 AM   #6
-kc-
LQ Newbie
 
Registered: Jun 2007
Distribution: Slackware
Posts: 21

Original Poster
Rep: Reputation: 15
Thanks nx5000,
any idea on what can be the purpose of close quickly the socket, then wait for the time given and close cleanly?

Many pages I found about netcat have examples with the -q option followed by a small delay, but none of them explain the purpose of the delay. Maybe if you don't know what it is, then you don't need it, but then why not just use q 0 combined with a sleep?
 
Old 07-03-2007, 04:43 PM   #7
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
The question is why use shutdown() rather than close().
Unfortunatly the last time I used this shutdown function was a long time ago.
Maybe to reconnect from the same source X port on host A to the same destination port Y on host B, to avoid TIME_WAIT state.
But this is pure speculation...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ls with recursive option and file name doesn't work FromFPan2Fire Linux - Newbie 7 01-05-2010 10:21 AM
traceroute - I option doesn't work nick623 Fedora 1 07-30-2006 03:14 AM
source routing hop points with netcat (-G option) crash88 Linux - Networking 0 05-11-2006 08:51 PM
NetCat 1.1 Where is it? Why doesn't it work? Somebody reply soon please Laptop2250 Linux - Software 2 11-04-2003 03:45 PM
netcat -e option Di0de Linux - Software 0 08-17-2003 12:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration