}
private static void usage(PrintStream out) {
- out.println("usage: dolda.jsvc.scgi.DirServer [-h] [-e CHARSET] [-d DATADIR] PORT");
+ out.println("usage: dolda.jsvc.scgi.DirServer [-h] [-B BINDADDR] [-e CHARSET] [-d DATADIR] PORT");
}
public static void main(String[] args) {
- PosixArgs opt = PosixArgs.getopt(args, "he:d:");
+ PosixArgs opt = PosixArgs.getopt(args, "he:d:B:");
if(opt == null) {
usage(System.err);
System.exit(1);
}
String charset = null;
File datroot = null;
+ InetAddress bindaddr;
+ try {
+ bindaddr = InetAddress.getLocalHost();
+ } catch(UnknownHostException e) {
+ throw(new Error("WTF?!", e));
+ }
for(char c : opt.parsed()) {
switch(c) {
case 'e':
System.exit(1);
}
break;
+ case 'B':
+ try {
+ bindaddr = InetAddress.getByName(opt.arg);
+ } catch(UnknownHostException e) {
+ System.err.println(opt.arg + ": no such host");
+ System.exit(1);
+ }
+ break;
case 'h':
usage(System.out);
return;
env.initvm();
int port = Integer.parseInt(opt.rest[0]);
ServerSocket sk;
+ SocketAddress saddr = new InetSocketAddress(bindaddr, port);
try {
- sk = new ServerSocket(port);
+ sk = new ServerSocket();
+ sk.bind(saddr);
} catch(IOException e) {
- System.err.println("could not bind to port " + port + ": " + e.getMessage());
+ System.err.println("could not bind to " + saddr + ": " + e.getMessage());
System.exit(1);
return; /* Because javac is stupid. :-/ */
}