示例#1
0
文件: client.c 项目: danimus/LSTuit
int main()
{
    int fd_in;
    char server[15];
    char port[15];
    pthread_t read_thread, write_thread;
    
    if ((fd_in = open(configfile, O_RDONLY)) < 0){
        panic_with_system_message("Error no se ha podido abrir el fichero de configuración");
    }
    
    LeerParametroHasta(fd_in,'\n',server);
    LeerParametroHasta(fd_in,'\n',port);
    LeerParametroHasta(fd_in,'\n',user);
    
    int sock = get_client_socket(server, port);
    if (sock < 0)
    {
        panic_with_user_message("Fallo en get_client_socket() ", "No se puede conectar");
    }
    printbanner();//Bienvenida si no han habido errores de arranque
    pthread_create(&read_thread, NULL,(void *) t_read, (void *) (uintptr_t)sock);
    pthread_create(&write_thread, NULL,(void *) t_write, (void *)(uintptr_t) sock);
    
    pthread_join(read_thread, NULL);
    pthread_join(write_thread, NULL);
    
    close(sock);
    exit(0);
}
示例#2
0
int
main (int argc, char **argv)
{
  int rc;
  char *pt;
  char *bversion;
  FILE *pidfile,*conffile;
  if(argc==2)
  {
      strmncpy(configfile,argv[1],sizeof(configfile));
  } else {
      strcpy(configfile,"psybnc.conf");  /* rcsid */
  }
  conffile=fopen(configfile,"r");
  if(conffile==NULL)
  {
     printf("Configuration File %s not found, aborting\nRun 'make menuconfig' for creating a configuration or create the file manually.\n",configfile); /* rcsid */
     exit (0x0);
  }
  fclose(conffile);
  readconfig();
  rc = getini("SYSTEM","LANGUAGE",INIFILE);  /* rcsid */
  if(rc!=0)
  {
      rc=loadlanguage("english");  /* rcsid */
  } else {
      rc=loadlanguage(value);  
      if(rc<0)
          rc=loadlanguage("english");  /* rcsid */
  }
  if(rc<0)
  {
      printf("Could not load language file, aborting.\n");  /* rcsid */
      exit(0x0);	  
  }
  printbanner();
  printf(lngtxt(991),configfile);
  printf(lngtxt(992),langname);
  ap_snprintf(logfile,sizeof(logfile),lngtxt(993));
  rc = getini(lngtxt(994),lngtxt(995),INIFILE);
  if (rc != 0) {
     printf("%s", lngtxt(996));
     exit (0x0);
  }
  listenport = atoi(value);
  rc = getini(lngtxt(997),"ME",INIFILE);
  if (rc < 0) {
     memset(value,0x0,sizeof(value));       
  }
  pt=strchr(value,' '); /* shortening bouncername to no spaces */
  if(pt)
      *pt=0;
  ap_snprintf(me,sizeof(me),"%s",value);
  rc = getini(lngtxt(998),lngtxt(999),INIFILE);
  if (rc < 0) {
     printf("%s", lngtxt(1000));
     ap_snprintf(value,sizeof(value),lngtxt(1001));
  }
  ap_snprintf(logfile,sizeof(logfile),"%s",value);
  oldfile(logfile);
  /* creating the socket-root */
  socketnode=(struct socketnodes *) pmalloc(sizeof(struct usernodes));
  socketnode->sock=NULL;
  socketnode->next=NULL;

  #ifdef IPV6
  /* set the default ipv6 preference for users without a PREFERIPV6 setting */
  rc = getini("SYSTEM", "DEFAULTIPV6", INIFILE);
  if (rc == 0)
  {
     defaultipv6 = atoi(value);
  }
  #endif

  /* creating the demon socket */
  rc = createlisteners();
  if (rc == 0) {
    printf("%s", lngtxt(1002));
    exit (0x0);
  }
  /* creating background */
  pidfile = fopen(lngtxt(1003),"w");
  if(pidfile==NULL)
  {
      printf("%s", lngtxt(1004));
      exit(0x0);
  }
  if(mainlog!=NULL)
  {
      fclose(mainlog);
      mainlog=NULL;
  }
  fflush(stdout);
  

  pid = fork();
  //pid = 0;
  if (pid < 0) {
  
  }
  if (pid == 0) {
     rc= errorhandling();
     makesalt();

#ifdef HAVE_SSL
     initSSL();
     pcontext;
#endif
     U_CREATE=0;
#ifdef PARTYCHANNEL
     /* partychannel setup */
     strmncpy(partytopic,lngtxt(1005),sizeof(partytopic));
     partyusers=NULL;
#endif
     /* creating the usernode-root */
     usernode=(struct usernodes *) pmalloc(sizeof(struct usernodes));
     usernode->uid=0;
     usernode->user=NULL;
     usernode->next=NULL;
     /* creating the newpeer-root */
     peernode=(struct peernodes *) pmalloc(sizeof(struct peernodes));
     peernode->uid=0;
     peernode->peer=NULL;
     peernode->next=NULL;
     /* creating the datalink-root */
     linknode=(struct linknodes *) pmalloc(sizeof(struct linknodes));
     linknode->uid=0;
     linknode->link=NULL;
     linknode->next=NULL;
     /* loading the users */
     loadusers();
     loadlinks();
     pcontext;
     /* loading the hostallows */
     hostallows=loadlist(lngtxt(1006),hostallows);
  }
  pcontext;
  if (pid) {
     bversion=buildversion();
     printf(lngtxt(1007),bversion,pid);
     p_log(LOG_INFO,-1,lngtxt(1008),bversion,pid);
     fprintf( pidfile,"%d\n",pid);
     fclose(pidfile);
     exit (0x0);
  }  
  pcontext;
//#ifndef BLOCKDNS
//  if(init_dns_core()==0)
//  {
//     dns_err(0,1);
//  }
//#endif

  p_dns_init();
  bncmain();
  return 0x0;
}