@@ -23,6 +23,7 @@ static int type = AF_INET;
2323static int keep ;
2424static int dmon ;
2525static int tmsec ;
26+ static int bport [3 ];
2627static unsigned int mark ;
2728
2829static char mport [16 ];
@@ -33,7 +34,6 @@ static char http[256];
3334
3435static const char * path ;
3536static const char * baddr ;
36- static const char * bport ;
3737static const char * taddr ;
3838static const char * tport ;
3939static const char * iface ;
@@ -58,7 +58,10 @@ hev_conf_help (void)
5858 " -f <mark> fwmark value (hex: 0x1, dec: 1, oct: 01)\n"
5959 "\n"
6060 "Bind options:\n"
61- " -b <port> port number for binding\n"
61+ " -b <port>[-port] port number range for binding\n"
62+ " - <0>: random allocation\n"
63+ " - <port>: specified\n"
64+ " - <port>-<port>: sequential allocation within the range\n"
6265 "\n"
6366 "Forward options:\n"
6467 " -T <timeout> port forwarding timeout in seconds\n"
@@ -104,7 +107,7 @@ hev_conf_init (int argc, char *argv[])
104107 mark = strtoul (optarg , NULL , 0 );
105108 break ;
106109 case 'b' :
107- bport = optarg ;
110+ sscanf ( optarg , "%u-%u" , & bport [ 0 ], & bport [ 1 ]) ;
108111 break ;
109112 case 'T' :
110113 tmsec = strtoul (optarg , NULL , 10 ) * 1000 ;
@@ -140,9 +143,13 @@ hev_conf_init (int argc, char *argv[])
140143 keep *= 1000 ;
141144 }
142145
143- if (!bport ) {
144- bport = "0" ;
146+ if (!bport [ 0 ] ) {
147+ bport [ 0 ] = 0 ;
145148 }
149+ if (!bport [1 ]) {
150+ bport [1 ] = bport [0 ];
151+ }
152+ bport [2 ] = bport [0 ];
146153
147154 if (iface && inet_pton (type , iface , & sa )) {
148155 baddr = iface ;
@@ -209,7 +216,16 @@ hev_conf_baddr (void)
209216const char *
210217hev_conf_bport (void )
211218{
212- return bport ;
219+ static char port [16 ];
220+
221+ snprintf (port , sizeof (port ) - 1 , "%u" , bport [2 ]);
222+
223+ bport [2 ] = bport [2 ] + 1 ;
224+ if (bport [2 ] > bport [1 ]) {
225+ bport [2 ] = bport [0 ];
226+ }
227+
228+ return port ;
213229}
214230
215231const char *
0 commit comments