pike.git / NT / tools / sprshd

version» Context lines:

pike.git/NT/tools/sprshd:117:    }    }    io->close("w");    destruct(io);   }      int main(int argc, string *argv)   {    if(argc<2)    { -  werror("Usage: sprshd <port> <host to accept connections from>\n"); +  werror("Usage: sprshd <port> <hosts to accept connections from>\n");    exit(1);    }    if(!bind((int)argv[1]))    {    werror("Failed to bind port.\n");    exit(1);    }    -  string *hosts=gethostbyname(argv[2])[1]; +  string *hosts=({}); +  for(int e=2;e<sizeof(argv);e++) +  { +  if(sscanf(argv[e],"%*d.%*d")==2) +  { +  hosts+=argv[e]; +  continue; +  } +  mixed tmp=gethostbyname(argv[e]); +  if(!tmp) +  { +  werror("Gethostbyname("+argv[e]+") failed.\n"); +  exit(1); +  } +  hosts+=tmp[1]; +  }       write("Ready.\n");    while(1)    {    if(object io=accept())    {    sscanf(io->query_address(),"%s ",string ip);    if(search(hosts, ip)==-1)    {    destruct(io);    continue;    }    thread_create(handle_incoming_connection,io);    }else{    werror("Accept failed "+errno()+"\n");    }    }   }