Beispiel #1
0
static void m_server( char *origin, char **argv, int argc, int srv )
{
	if( argc > 2 ) {
		do_server( argv[0], origin, argv[1], argv[2], NULL, srv );
	} else {
		do_server( argv[0], origin, NULL, argv[1], NULL, srv );
	}
}
Beispiel #2
0
/* EVENT: SERVER */
int denora_event_server(char *source, int ac, char **av)
{
    if (denora->protocoldebug) {
        protocol_debug(source, ac, av);
    }
    if (!stricmp(av[1], "1")) {
        denora->uplink = sstrdup(av[0]);
        do_server(source, av[0], av[1], av[2], NULL);
        return MOD_CONT;
    }
    do_server(source, av[0], av[1], av[2], NULL);
    return MOD_CONT;
}
Beispiel #3
0
int main(int argc, char *argv[]) {
    WSAData wsaData;
    int nCode;
    int server_port = DEFAULT_PORT;
    
    if ((nCode = WSAStartup(MAKEWORD(2, 2), &wsaData)) != 0) {
        std::cerr<<"WSAStartup() returned error code "<<nCode<<"."<<std::endl;
        return 255;
    }
    
    const char SEP = '\\';
    char *progName = argv[0];
    // skip over the path separators
    for (char *p = argv[0]; *p != '\0'; p++) {
        if (*p == SEP) progName = p + 1;
    }
    if (argc >= 2) {
        sscanf(argv[1], "%i", &server_port);
        
    }
    int rc = do_server(progName, server_port);
    
    WSACleanup();
    return rc;
}
Beispiel #4
0
int			monitor(t_init *data)
{
  t_player_lst		*tmp;
  int			ret;
  struct timeval	tv;
  int			stay;

  init_monitor(data, &tv, &ret, &tmp);
  if ((select(max(data) + 1, &(data->read), &(data->write), NULL, &tv)) == -1)
    return (merror("select"));
  if (FD_ISSET(data->socket, &(data->read)))
    ret = do_server(data);
  else
    {
      stay = 1;
      while (stay && tmp != NULL)
	{
	  if (ret == 0 && FD_ISSET(tmp->player.fd, &(data->read)))
	    stay = do_client(tmp->player.fd, &tmp, data);
	  else
	    ret = 0;
	  tmp = tmp->next;
	}
    }
  check_timer(data);
  test_end(data);
  return (0);
}
int main(int argc, char** argv) {
    if (argc == 1) {
        return do_server();
    }

    bool dump_backtrace = false;
    bool have_tid = false;
    pid_t tid = 0;
    for (int i = 1; i < argc; i++) {
        if (!strcmp(argv[i], "-b")) {
            dump_backtrace = true;
        } else if (!have_tid) {
            tid = atoi(argv[i]);
            have_tid = true;
        } else {
            usage();
            return 1;
        }
    }
    if (!have_tid) {
        usage();
        return 1;
    }
    return do_explicit_dump(tid, dump_backtrace);
}
Beispiel #6
0
void servmgr (void)
{
  int status;
  BINKD_CONFIG *config;

  srand(time(0));
  setproctitle ("server manager");
  Log (4, "servmgr started");

#if defined(HAVE_FORK) && !defined(HAVE_THREADS)
  blocksig();
  signal (SIGCHLD, sighandler);
#endif

  /* Loop on socket (listen can be changed by reload)
   * do_server() will return 0 to restart and -1 to terminate
   */
  do
  {
    config = lock_current_config();
    status = do_server(config);
    unlock_config_structure(config, 0);
  } while (status == 0 && !binkd_exit);
  Log(4, "downing servmgr...");
  pidsmgr = 0;
  PostSem(&eothread);
}
Beispiel #7
0
int main(int argc, char *argv[])
{
	char ip[128];
	int port = 9001, ch;

	snprintf(ip, sizeof(ip), "127.0.0.1");

	while ((ch = getopt(argc, argv, "hs:p:")) > 0) {
		switch (ch) {
		case 'h':
			usage(argv[0]);
			return 0;
		case 's':
			snprintf(ip, sizeof(ip), "%s", optarg);
			break;
		case 'p':
			port = atoi(optarg);
			break;
		default:
			break;
		}
	}

	SOCKET ls = socket_listen(ip, port);
	if (ls == INVALID_SOCKET) {
		printf("tcplisten error %s\r\n", strerror(errno));
		return 1;
	}
	printf("listen %s:%d ok\r\n", ip, port);

	go[=] { do_server(ls); };

	g_Scheduler.RunUntilNoTask();
	return 0;
}
int main(int argc, char** argv) {
  union selinux_callback cb;
  if (argc == 1) {
    selinux_enabled = is_selinux_enabled();
    cb.func_log = selinux_log_callback;
    selinux_set_callback(SELINUX_CB_LOG, cb);
    return do_server();
  }

  bool dump_backtrace = false;
  bool have_tid = false;
  pid_t tid = 0;
  for (int i = 1; i < argc; i++) {
    if (!strcmp(argv[i], "-b")) {
      dump_backtrace = true;
    } else if (!have_tid) {
      tid = atoi(argv[i]);
      have_tid = true;
    } else {
      usage();
      return 1;
    }
  }
  if (!have_tid) {
    usage();
    return 1;
  }
  return do_explicit_dump(tid, dump_backtrace);
}
Beispiel #9
0
int xanadu_event_server(char *source, int ac, char **av)
{
    if (!stricmp(av[1], "1")) {
        uplink = sstrdup(av[0]);
    }
    do_server(source, av[0], av[1], av[2], NULL);
    return MOD_CONT;
}
Beispiel #10
0
int main(void)
{
	int listenfd;
    //设置一个监听套接字
	if((listenfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP))<0)
		ERR_EXIT("socket");
    //初始化服务器地址
	struct sockaddr_in servaddr;
	memset(&servaddr, 0, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(5188);
	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
    
    //设置在TIME_WAIT消失前可连接
    int on = 1;
    if(setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))<0)
        ;

    //绑定监听套接字和服务器地址
	if(bind(listenfd, (struct sockaddr*)&servaddr, sizeof(servaddr))<0)
		ERR_EXIT("bind");
    //
	if(listen(listenfd,SOMAXCONN)<0)
		ERR_EXIT("listen");

    //设置对等方套接字地址
	struct sockaddr_in peeraddr;
	socklen_t peerlen = sizeof(peeraddr);

    int conn;//已连接套接字
    pid_t pid;
    while(1)
    {
        //从完成三次握手的队列中拿出已连接套接字,放在conn中
	    if((conn = accept(listenfd, (struct sockaddr*)&peeraddr, &peerlen))<0)
		    ERR_EXIT("accept");

        // 打印出连接的客户端的地址和端口号
        printf("ip=%s, port=%d\n",inet_ntoa(peeraddr.sin_addr), ntohs(peeraddr.sin_port));

        //多线程,子线程用于连接,父线程用于继续从完成三次握手的队列中拿出套接字
        pid = fork();
        if(pid == -1)
            ERR_EXIT("fork");
        if(pid == 0)
        {
            //关闭监听套接字
            close(listenfd);
            do_server(conn);
            exit(EXIT_SUCCESS);
        }
        else
            //关闭已连接套接字
            close(conn);
    } 

	return 0;
}
Beispiel #11
0
void sorcery_cmd_connect(void)
{
    me_server =
        do_server(NULL, ServerName, (char *) "0", ServerDesc, NULL);

    sorcery_cmd_capab();
    sorcery_cmd_pass(RemotePassword);
    sorcery_cmd_server(ServerName, 1, ServerDesc);
}
Beispiel #12
0
int main(int argc, char *argv[])
{
    if( argc > 1 )
        do_client(argv[1]);
    else
        do_server();

    return 0;
}
Beispiel #13
0
int main(int argc, char **argv)
{
    pid_t pid;

    pid = fork();
    
    if (pid == -1) {
        perror("fork");
        exit(EXIT_FAILURE);        
    } else if (pid == 0) {
        // クライアント(子プロセス)
        int shmfd;
        
        // Unix ドメインクライントを作り shmfd を受信
        shmfd = do_client();

        // shmfd を使って mmap() を行い共有メモリに書き込み
        void *addr;
        addr = mmap(NULL, TEMPFILE_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0);
        if (addr == MAP_FAILED) {
            perror("mmap");
            exit(EXIT_FAILURE);
        }
        sprintf((char*)addr, "ABCDEFG");

        close(shmfd);        
    }  else {
        // サーバー(親プロセス)

        // 共有ファイルの file descriptor を取得
        int shmfd;
        shmfd = create_shm_file();

        // Unix ドメインサーバを作り shmfd を送信
        do_server(shmfd);

        // 子プロセスの終了を待つ
        if (waitpid(pid, NULL, 0) == -1) {
            perror("waitpid");
            exit(EXIT_FAILURE);
        }

        // shmfd を使って mmap() を行い共有メモリの内容を表示
        void *addr;
        addr = mmap(NULL, TEMPFILE_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0);
        if (addr == MAP_FAILED) {
            perror("mmap");
            exit(EXIT_FAILURE);
        }
        close(shmfd);

        // 子プロセスが書き込んだ内容が見えれば成功
        puts((const char*)addr);
    }

    return 0;
}
Beispiel #14
0
void plexus_cmd_connect(void)
{
	/* Make myself known to myself in the serverlist */
	if (UseTS6 && Numeric)
	{
		me_server =
		    do_server(NULL, ServerName, (char *) "0", ServerDesc, TS6SID);
	}
	else
	{
		me_server =
		    do_server(NULL, ServerName, (char *) "0", ServerDesc, NULL);
	}

	plexus_cmd_pass(RemotePassword);
	plexus_cmd_capab();
	plexus_cmd_server(ServerName, 1, ServerDesc);
	plexus_cmd_svinfo();
}
Beispiel #15
0
void plexus_cmd_connect(void)
{
	me_server =
	    do_server(NULL, ServerName, (char *) "0", ServerDesc, NULL);

	plexus_cmd_pass(RemotePassword);
	plexus_cmd_capab();
	plexus_cmd_server(ServerName, 1, ServerDesc);
	plexus_cmd_svinfo();
}
Beispiel #16
0
void inspircd_cmd_connect(void)
{
    me_server =
        do_server(NULL, ServerName, (char *) "0", ServerDesc, NULL);

    inspircd_cmd_capab();
    send_cmd(NULL, "SERVER %s %s %d :%s", ServerName, RemotePassword, 0,
             ServerDesc);
    send_cmd(NULL, "BURST");
    send_cmd(ServerName, "VERSION :Denora");
}
Beispiel #17
0
int main (int argc, char **argv)
{
    int fd_cli = -1, fd_lis = -1, fd_srv = -1;
    int port = 5190;

    fd_lis = do_listen (&port);
    while (1)
    {
        printf ("Waiting for connections... (login)\n");
        fd_cli = do_accept (fd_lis);
        fd_srv = do_server ("login.icq.com", 5190);
        do_exchange (fd_cli, fd_srv, port, argc < 2);
        printf ("Waiting for connections... (session)\n");
        fd_cli = do_accept (fd_lis);
        fd_srv = do_server (use_host, use_port);
        do_exchange (fd_cli, fd_srv, port, argc < 2);
        fflush (stdout);
    }
    return 0;
}
Beispiel #18
0
void bahamut_cmd_connect(void)
{
    me_server =
        do_server(NULL, ServerName, (char *) "0", ServerDesc, NULL);

    bahamut_cmd_pass(RemotePassword);
    bahamut_cmd_capab();
    bahamut_cmd_server(ServerName, 1, ServerDesc);
    bahamut_cmd_svinfo();
    bahamut_cmd_burst();
}
Beispiel #19
0
/* (AB S trystan.nomadirc.net 2 0 1106520454 P10 ACAP] +h :Test Server) */
int denora_event_server(char *source, int ac, char **av)
{
    Server *s;
    char uplinknum[3];
    *uplinknum = '\0';

    if (denora->protocoldebug) {
        protocol_debug(source, ac, av);
    }
    strlcpy(uplinknum, av[5], sizeof(uplinknum));

    if (!stricmp(av[1], "1")) {
        denora->uplink = sstrdup(av[0]);
        do_server(source, av[0], av[1], av[7], uplinknum);
    } else {
        s = server_find(source);
        do_server((s ? s->name : source), av[0], av[1], av[7], uplinknum);
    }
    return MOD_CONT;
}
int main(int argc,char **argv)
{
  if (argc == 2) {
    if (!strcmp(argv[1],"client"))
      return do_client();
    else if (!strcmp(argv[1],"server"))
      return do_server();
  }

  printf("Usage: system_transport-test <client / server>\n");
  return -1;
}
Beispiel #21
0
void asuka_cmd_connect(void)
{
    if (!BadPtr(Numeric)) {
        inttobase64(p10id, atoi(Numeric), 2);
        me_server =
            do_server(NULL, ServerName, (char *) "0", ServerDesc, p10id);
        asuka_cmd_pass(RemotePassword);
        asuka_cmd_server(ServerName, 1, ServerDesc);
    } else {
        alog(LOG_NORMAL, "Numeric is required for P10 ircds");
        exit(1);
    }
}
Beispiel #22
0
/* EVENT: SERVER */
int denora_event_server(char *source, int ac, char **av)
{
	if (denora->protocoldebug)
	{
		protocol_debug(source, ac, av);
	}
	if (!denora->uplink)
	{
		denora->uplink = sstrdup(av[0]);
	}
	do_server(source, av[0], av[1], av[2], (!stricmp(av[1], "1") && UseTS6 && TS6UPLINK ? TS6UPLINK : NULL));
	return MOD_CONT;
}
Beispiel #23
0
static void m_server( char *origin, char **argv, int argc, int srv )
{
	char *s = argv[argc-1];
	if( *origin== 0 )
	{
		/* server desc from uplink includes extra info so we need to 
		   strip protocol, flags and numeric. We can use the first
		   space to do this*/
		while( *s != ' ' )
			s++;
		/* Strip the now leading space */
		s++;
	}
	if( argc > 3 )
	{
		do_server( argv[0], origin, argv[1], argv[2], s, srv );
	}
	else
	{
		do_server( argv[0], origin, argv[1], NULL, s, srv );
	}
}
Beispiel #24
0
int main(int argc, char *argv[])
{
	int rv;

	memset(&cl, 0, sizeof(cl));
	strncpy(cl.configfile, BOOTH_DEFAULT_CONF,     BOOTH_PATH_LEN - 1);
	strncpy(cl.lockfile,   BOOTH_DEFAULT_LOCKFILE, BOOTH_PATH_LEN - 1);

	rv = read_arguments(argc, argv);
	if (rv < 0)
		goto out;

	if (cl.type == ACT_CLIENT) {
		cl_log_enable_stderr(TRUE);
		cl_log_set_facility(0);
	} else {
		cl_log_set_entity(logging_entity);
		cl_log_enable_stderr(debug_level ? TRUE : FALSE);
		cl_log_set_facility(HA_LOG_FACILITY);
	}
	cl_inherit_logging_environment(0);

	switch (cl.type) {
	case ACT_ARBITRATOR:
		rv = do_server(ARBITRATOR);
		break;

	case ACT_SITE:
		rv = do_server(SITE);
		break;

	case ACT_CLIENT:
		rv = do_client();
		break;
	}

out:
	return rv ? EXIT_FAILURE : EXIT_SUCCESS;
}
Beispiel #25
0
void inspircd_cmd_connect(void)
{
    me_server =
        do_server(NULL, ServerName, (char *) "0", ServerDesc, NULL);

    inspircd_cmd_capab();
    send_cmd(NULL, "SERVER %s %s %d :%s", ServerName, RemotePassword, 0,
             ServerDesc);
    send_cmd(NULL, "BURST");
    send_cmd(ServerName,
             "VERSION :Denora-%s %s :%s -- build #%s, compiled %s %s",
             denora->version, ServerName, ircd->name, denora->build,
             denora->date, denora->time);
}
Beispiel #26
0
int 
main(int argc, char *argv[])
{

   if (argc < 3) {
      usage(argv);
      exit(1);
   }

   isserver = argv[1][0] == 's';
   if (isserver) {
      if (argc != 3) {
         usage(argv);
         exit(1);
      }
      srcportno = atoi (argv[2]);
      netcardno = __sysinfo.si_nnetworks - 1;
      startinpackets = __sysinfo.si_networks[netcardno].rcvs;
      startoutpackets = __sysinfo.si_networks[netcardno].xmits;
      do_server ();

   } else {
      if (argc < 6) {
         usage(argv);
         exit(1);
      }
      host = argv[2];
      myhost = argv[3];
      pktcnt = atoi(argv[4]);
      pktdata = atoi(argv[5]);
      if (argc >= 7) {
         ackfreq = atoi(argv[6]);
      }
      if (argc >= 8) {
         ackdata = atoi(argv[7]);
      }

      do_client ();
   }

   if (netcardno >= 0) {
      printf ("%s done (netin %qd, netout %qd)\n", argv[0], (__sysinfo.si_networks[netcardno].rcvs - startinpackets), (__sysinfo.si_networks[netcardno].xmits - startoutpackets));
   } else {
      printf ("%s done (netcardno %d)\n", argv[0], netcardno);
   }

   return 0;
}
Beispiel #27
0
int main(int argc, char *argv[])
{
	if (!do_options(&argc, &argv))
		return EXIT_FAILURE;

	switch (mode) {
	case CLIENT:
		do_client(host, port, files);
		break;
	case SERVER:
		do_server(port);
		break;
	}

	return EXIT_SUCCESS;
}
Beispiel #28
0
void* server_thread(void *arg)
{
    SSL *ssl = (SSL *)arg;

    pthread_detach(pthread_self());
    if(SSL_accept(ssl) <= 0)
        log_err("Error accepting SSL connection.");
    fprintf(stderr, "SSL Connection opened.\n");
    if(do_server(ssl))
        SSL_shutdown(ssl);
    else
        SSL_clear(ssl);
    fprintf(stderr, "SSL Connection closed.\n");
    SSL_free(ssl);
    ERR_remove_state(0);
}
Beispiel #29
0
int denora_event_sid(char *source, int ac, char **av)
{
	Server *s;

	/* :42X SID trystan.nomadirc.net 2 43X :ircd-ratbox test server */

	if (denora->protocoldebug)
	{
		protocol_debug(source, ac, av);
	}

	s = server_find(source);

	do_server(s->name, av[0], av[1], av[3], av[2]);
	return MOD_CONT;
}
int
main(int argc, char *argv[])
{
	int err;

	ct_arg0 = argv[0];

	if (argc != 2) {
		usage();
	}

	if (strcmp(argv[1], "server") == 0) {
		err = do_server(ct_port);
	} else {
		err = do_client(ct_port, argv[1]);
	}

	return (err);
}