示例#1
0
int CcsServer_recvRequest(CcsImplHeader *hdr,void **reqData) 
{
  char ip_str[200];
  skt_ip_t ip;
  unsigned int port,ret=1;
  SOCKET fd;
  skt_abortFn old=skt_set_abort(req_abortFn);

  CCSDBG(("CCS Receiving connection...\n"));
  fd=skt_accept(ccs_server_fd,&ip,&port);

  CCSDBG(("CCS   Connected to IP=%s, port=%d...\n",skt_print_ip(ip_str,ip),port));
  hdr->attr.ip=ip;
  hdr->attr.port=ChMessageInt_new(port);

  if (0==CcsServer_recvRequestData(fd,hdr,reqData))
  {
    fprintf(stdout,"During CCS Client IP:port (%s:%d) processing.\n",
	    skt_print_ip(ip_str,ip),
	    port);
    skt_close(fd);
    ret=0;
  }

  CCSDBG(("CCS   Got all %d data bytes for request.\n",reqBytes));
  skt_set_abort(old);

  return ret;
}
示例#2
0
/*Make a new Ccs Server socket, on the given port.
Returns the actual port and IP address.
*/
void CcsServer_new(skt_ip_t *ret_ip,int *use_port,const char *authFile)
{
  char ip_str[200];
  skt_ip_t ip;
  unsigned int port=0;if (use_port!=NULL) port=*use_port;
  
  CCS_AUTH_new(&ccs_clientlist);
  security=CcsSecMan_default(authFile);
  skt_init();
  ip=skt_my_ip();
  ccs_server_fd=skt_server(&port);
  printf("ccs: %s\nccs: Server IP = %s, Server port = %u $\n", 
           CMK_CCS_VERSION, skt_print_ip(ip_str,ip), port);
  fflush(stdout);
  if (ret_ip!=NULL) *ret_ip=ip;
  if (use_port!=NULL) *use_port=port;
}
示例#3
0
int main() {
	unsigned int port=1234;
	SERVER_SOCKET serv=skt_server(&port);
	while (1) { /* be a server */
		std::cout<<"Listening on port "<<port<<std::endl;
	
		skt_ip_t client_ip; unsigned int client_port=0;
		SOCKET s=skt_accept(serv,&client_ip,&client_port);
		std::cout<<"Client connected from "<<skt_print_ip(client_ip)<<":"<<client_port<<std::endl;
		
		bool intranet=false;
		if (client_ip.data[0]==127 || client_ip.data[0]==10) 
			intranet=true;

		try {
			handle_client(s,intranet);
		} 
		catch (std::runtime_error &e) {
			std::cout<<"Client error: "<<e.what()<<"\n";
		}
	}
}
示例#4
0
/* Logs the requests of clients, as they go by. */
bool osl::html_logger::respond(osl::http_served_client &client) {
	char ip_string[100]; skt_print_ip(ip_string,client.get_ip());

	char date_string[100]; 
	time_t t; time(&t);
	const static char *month_names[]={
		"Jan","Feb","Mar","Apr","May","Jun",
		"Jul","Aug","Sep","Oct","Nov","Dec"};
#if _WIN32 /* might use localtime_s on newer Windows compilers... */
	struct tm &lt=*localtime(&t);
#else
	struct tm lt;
	localtime_r(&t,&lt);
#endif
	snprintf(date_string,100,
		"%02d/%s/%d:%02d:%02d:%02d LOCALTIME",
		lt.tm_mday,month_names[lt.tm_mon],lt.tm_year+1900,
		lt.tm_hour,lt.tm_min,lt.tm_sec);

	out<<ip_string<<" - - ["<<date_string<<"] \"GET "<<client.get_path()<<" HTTP/1.1\" 200 1 \""<<client.get_header("Referer")<<"\" \""<<client.get_header("User-Agent")<<"\"\n";

	return false; /* we don't service clients, just log them */
}