コード例 #1
0
ファイル: p_link.c プロジェクト: nawawi/psybnc
int relay(int nlink)
{
    pcontext;
    if(currentsocket->sock->syssock==datalink(nlink)->outsock)
	writesock(datalink(nlink)->insock,ircbuf);
    if(currentsocket->sock->syssock==datalink(nlink)->insock)
	writesock(datalink(nlink)->outsock,ircbuf);
}
コード例 #2
0
ファイル: mid_tcp.c プロジェクト: mildrock/netBankGateWay
int mid_tcp( char * ipaddr,int port,char * mgid,char  *inbuf,int inlen,char  *outbuf,int * outlen)
   {
   int    clientfd;

   /*建立连接*/
   clientfd = tcp_client_init(ipaddr ,(int ) port);
   if (clientfd < 0)
      {
      printf("tcp_client_init error!\n");
      memcpy(mgid,"0001",4);
      return(-1);
      }

   if (writesock(clientfd,inbuf,inlen) != inlen)
     {
      printf("writesock error!\n");
      memcpy(mgid,"0002",4);
      tcp_close(clientfd);
      return(-2) ;
     }

  *outlen = readsock(clientfd,outbuf); 
  if (*outlen < 0) 
     {
      printf("readsock error! return[%d]\n",*outlen);
      memcpy(mgid,"0003",4);
      tcp_close(clientfd);
      return(-3);
     }

   /*close tcp connect*/
   memcpy(mgid,"0000",4);
   tcp_close(clientfd);
   return(0);
   }
コード例 #3
0
int ircdboost(char *host, int port, char *nick)
{
    int sock;
    char buf[2048];
    char *pt;
    printf("Step 2: Connecting to the IRC Server.\n");
    sock=tcpconnect(lookup(host),port,10);

    if (sock==-1) {
	printf("Error: cant connect\n");
	exit(0x0);
    }
    printf("Step 3: Connected.. sending user / join\n");
    /* the star is very very important */
    writesock(sock,"USER o a a :a\r\n");
    snprintf(buf,sizeof(buf),"NICK %s\r\n",nick);
    writesock(sock,buf);
    snprintf(buf,sizeof(buf),"WHOIS kbnn%d\r\n",lookup(host));
    writesock(sock,buf);
    /* this joins are needed to broadcast the user to the connected servers */
    writesock(sock,"JOIN #sex\r\n"); /* yeah, right */
    writesock(sock,"JOIN #showdown\r\n"); /* yeah, right */
    writesock(sock,"JOIN #funfactory\r\n"); /* yeah, right */
    writesock(sock,"JOIN #usa\r\n"); /* yeah, right */
    writesock(sock,"JOIN #flirt.de\r\n"); /* yeah, right */
    writesock(sock,"JOIN 0\r\n"); /* yeah, right */
    printf("Step 4: Please press control+break to release the split.\n");
    while (readsock(sock,buf,sizeof(buf)) >=0)
    {
	pt=strstr(buf,"PING");
	if (pt==buf)
	{
	    writesock(sock,"PONG :PPP\r\n");
	}
	pt=strstr(buf,"ERROR");
	if (pt==buf) break;
	printf(buf);
    }
    close(sock);
}
コード例 #4
0
ファイル: parallel.c プロジェクト: JNicL/MPIProject
static inline void oldcore(const int core)
{
  int fd = child[core].fd;
  seq_t seq = child[core].seq;
  child[core].seq = mem_seq;

  MASTER("sending mem_hel(%p#%ld) to core %d",
    mem.h, mem.he - mem.h, core);
  writesock(fd, mem.h, mem.he - mem.h);
  seq ^= mem_seq;
  if( SEQ_ANGLE(seq) ) {
    MASTER("sending mem_angle(%p#%ld+%p#%ld) to core %d",
      mem.v, mem.ve - mem.v, mem.a, mem.ae - mem.a, core);
    writesock(fd, mem.v, mem.ve - mem.v);
    writesock(fd, mem.a, mem.ae - mem.a);
  }
  if( SEQ_S(seq) ) {
    MASTER("sending mem_s(%p#%ld) to core %d",
      mem.s, mem.se - mem.s, core);
    writesock(fd, mem.s, mem.se - mem.s);
  }
}
コード例 #5
0
ファイル: parallel.c プロジェクト: JNicL/MPIProject
static inline void newcore(subroutine foo, const int flags)
{
  int fd[2];
  pid_t pid;
  int core = nlaunched++;

  assert(
    socketpair(AF_LOCAL, SOCK_STREAM, 0, fd) != -1 &&
    (pid = fork()) != -1 );

  if( pid ) {
    MASTER("forked core %d pid %d pipe %d(master) -> %d(worker) seq %llx",
      core, pid, fd[0], fd[1], mem_seq);
    close(fd[1]);
    child[core].fd = fd[0];
    child[core].seq = mem_seq;
    FD_SET(fd[0], &children);
    fdmax = IMax(fd[0], fdmax);
    return;
  }

  close(fd[0]);

  for( ; ; ) {
    RealType res[NCOMP];
    seq_t seq = mem_seq;

    res[0] = res[1] = 0;
    foo(res, &flags);
    WORKER(core, "writing result(%ld)", sizeof res);
    writesock(fd[1], res, sizeof res);

    WORKER(core, "reading mem_hel(%p#%ld)", mem.h, mem.he - mem.h);
    if( !readsock(fd[1], mem.h, mem.he - mem.h) ) exit(0);
    WORKER(core, "seq %llx  new %llx", seq, mem_seq);
    seq ^= mem_seq;
    if( SEQ_ANGLE(seq) ) {
      WORKER(core, "reading mem_angle(%p#%ld+%p#%ld)",
        mem.v, mem.ve - mem.v, mem.a, mem.ae - mem.a);
      readsock(fd[1], mem.v, mem.ve - mem.v);
      readsock(fd[1], mem.a, mem.ae - mem.a);
      restorecache_();
    }
    if( SEQ_S(seq) ) {
      WORKER(core, "reading mem_s(%p#%ld)", mem.s, mem.se - mem.s);
      readsock(fd[1], mem.s, mem.se - mem.s);
      clearcache_();
    }
    seq = mem_seq;
  }
}
コード例 #6
0
ファイル: p_link.c プロジェクト: gandaro/piebnc
int processlink(int nlink, int sock, int state)
{
    struct usernodes *th;
    struct linknodes *lh;
    int rc;
    char *pt,*pt2;
#ifdef PARTYCHANNEL
    int rr = 0;
    char buf[600] = "";
    char buf1[400] = "";
#endif
    char l;
    char o[]="->";
    char i[]="<-";
    char r[]="R ";
    char sic[500];
    int last;
    pcontext;
    if (state!=STD_CONN) return 0x0;
    parse();
    pcontext;
    if (!ifcommand("IAM") && !ifcommand(lngtxt(521))) broadcast(nlink); /* if its the IAM message, it does NOT
						get broadcasted */
    pcontext;
    pt=strchr(ircto,'@');
#ifdef PARTYCHANNEL
    if(pt==NULL) pt=strchr(ircto,'*');
#endif
    pcontext;
    if (pt!=NULL) 
    {
	*pt=0;
	pt++;
	if (strmcmp(pt,me)!=0 || (*ircto=='*' && strlen(pt)==1))
	{
	    pcontext;
	    if (ifcommand(lngtxt(522)))
	    {
		rc=checkuser(ircto);
		if (rc==0)
		{
		    ap_snprintf(ircbuf,sizeof(ircbuf),lngtxt(523),me,ircnick,irchost,ircto);
		    broadcast(0);	    
		    return 0x0;
		}
#ifdef PARTYCHANNEL
		ssnprintf(user(rc)->insock,lngtxt(524),ircnick,irchost,user(rc)->nick,irccontent);
#else
		ssnprintf(user(rc)->insock,lngtxt(525),ircnick,irchost,user(rc)->nick,irccontent);
#endif
		return 0x0;
	    }
	    pcontext;
	    if (ifcommand(lngtxt(526)))
	    {
		if(strstr(irccontent,o)!=NULL || strstr(irccontent,i)!=NULL) /* this is a listlink for the topology */
		{
		    pt=strchr(irccontent,'[');
		    if(pt!=NULL)
		    {
			pt++;
			pt2=strstr(pt,"]*");
			if(pt2!=NULL)
			{
			    *pt2=0;
			    strmncpy(sic,pt,sizeof(sic)); /* in sic we got the first linker */
			    pt2++;
			    pt=strstr(pt2,o);
			    if(pt==NULL) pt=strstr(pt2,i);
			    if(pt==NULL) return 0x0;		    
			    pt2=strchr(pt+3,' ');
			    if(pt2!=NULL)
			    {
				*pt2=0;
				if(strstr(pt,o)==pt)
				{
				    pt+=3;
				    addtopology(sic,pt);
				} else {
				    pt+=3;
				    addtopology(pt,sic);
				}
				return 0x0;
			    }
			}
		    }
		}
		pcontext;
#ifdef PARTYCHANNEL
		if(strstr(ircbuf,lngtxt(527))==ircbuf)
		{
		    if(*ircto=='*') /* systemrequest */
		    {
			pt=strchr(irccontent,']');
			if(pt!=NULL)
			{
			    pt+=2;
			    if(*pt=='*')
			    {
				pt2=strchr(pt,'(');
				if (pt2!=NULL)
				{
				    pt+=2;
				    *pt2=0;
				    ap_snprintf(buf,sizeof(buf),lngtxt(528),pt,irchost);
				    if(partyadd(buf)==1)
				    {
					ap_snprintf(buf1,sizeof(buf1),"%s%s\r\n",lngtxt(529),PARTYCHAN);
					ap_snprintf(buf,sizeof(buf),buf1,pt,irchost,pt,irchost);
					th=usernode;
					while(th!=NULL)
					{
					    rc=th->uid;
					    if(user(rc)->instate==STD_CONN && user(rc)->sysmsg==1 && user(rc)->parent==0)
					    {
						writesock(user(rc)->insock,buf);
					    }
					    th=th->next;
					}
					return 0x0;
				    }
				}
			    }
			}
		    }
		}
#endif
		rc=checkuser(ircto);
		if (rc!=0)
		{
		    ssnprintf(user(rc)->insock,lngtxt(530),ircnick,user(rc)->nick,irccontent);
		    return 0x0;
		}
	    }
	}
    }
    pcontext;
    if (ifcommand("IAM"))
    {
	if(*ircnick==0 || strchr(ircnick,' ')!=NULL || strchr(ircnick,'@')!=NULL || strchr(ircnick,'*')!=NULL)
	{
	    sysparty(lngtxt(531));
	    killsocket(sock);
	    datalink(nlink)->instate=STD_NOCON;
	    datalink(nlink)->outstate=STD_NOCON;
	    datalink(nlink)->insock=0;
	    datalink(nlink)->outsock=0;
	    clearlink(nlink);
	    eraselinkini(nlink);
	    return 0x0;
	}
	strmncpy(datalink(nlink)->iam,ircnick,sizeof(datalink(nlink)->iam));
	addtopology(me,datalink(nlink)->iam);
	writelink(nlink);
    }
    pcontext;
    if (ifcommand(lngtxt(532)))
    {
	if (strmcmp(me,ircto)!=0)
	{
	    p_log(LOG_ERROR,-1,lngtxt(533),
	      nlink,datalink(nlink)->host,datalink(nlink)->port);
	    killsocket(sock);
	    removetopology(me,datalink(nlink)->iam,lostlink);
	    datalink(nlink)->instate=STD_NOCON;
	    datalink(nlink)->outstate=STD_NOCON;
	    datalink(nlink)->insock=0;
	    datalink(nlink)->outsock=0;
	    clearlink(nlink);
	    eraselinkini(nlink);
	    return 0x0;	
	}
    }
    pcontext;
    if (ifcommand(lngtxt(534)))
    {
	th=usernode;
	while (th!=NULL) {
	    rc=th->uid;
	    if ((user(rc)->instate==STD_CONN && user(rc)->parent==0 && user(rc)->sysmsg==1) || rc==1)
	    {
		strmncpy(sic,irccontent,sizeof(sic));
#ifdef PARTYCHANNEL
		strmncpy(irccommand,lngtxt(535),sizeof(irccommand));
		strmncpy(ircto,PARTYCHAN,sizeof(ircto));
		if(strlen(ircto+1)<sizeof(ircto))
		    strcat(ircto," ");
#endif
		/* keeping being compatible with earlier versions requires this */
		if(strlen(ircnick)==6 && strstr(ircnick,lngtxt(536))==ircnick)
		{
#ifdef PARTYCHANNEL
		    if(strstr(irccontent,lngtxt(537))!=NULL)
		    {
			pt=strstr(irccontent,lngtxt(538));
			if(pt!=NULL)
			{
			    pt+=5;
			    pt2=strchr(pt,' ');
			    if (pt2!=NULL) *pt2=0;
			    strmncpy(ircnick,pt,sizeof(ircnick));
			    ap_snprintf(buf,sizeof(buf),lngtxt(539),pt,irchost);
			    strcpy(irccommand,"JOIN");
			    strmncpy(irccontent,PARTYCHAN,sizeof(irccontent));
			    *ircto=0;
			    if(rr==0) { partyadd(buf); rr=1; }
			}
		    }
		    if(strstr(irccontent,lngtxt(540))!=NULL)    
		    {
			pt=strstr(irccontent,lngtxt(541));
			if(pt!=NULL)
			{
			    pt+=5;
			    pt2=strchr(pt,' ');
			    if (pt2!=NULL) *pt2=0;
			    strmncpy(ircnick,pt,sizeof(ircnick));
			    ap_snprintf(buf,sizeof(buf),lngtxt(542),pt,irchost);
			    strcpy(irccommand,"PART");
			    strmncpy(irccontent,lngtxt(543),sizeof(irccontent));
			    if(rr==0) { partyremove(buf); rr=1; }
			}
		    }
#endif
		    if(strstr(irccontent,lngtxt(544))==irccontent)
		    {
			ap_snprintf(ircbuf,sizeof(ircbuf),lngtxt(545),me);
			broadcast(0);
			return 0x0;
		    }
		    if(strstr(irccontent,lngtxt(546))==irccontent)    
		    {
			pt=irccontent+11;
			pt2=strchr(pt,')');
			if(pt2!=NULL) *pt2=0;
			removetopology(irchost,pt,lostlink);
			if(pt2!=NULL) *pt2=')';
		    }
		}
#ifdef PARTYCHANNEL
		ap_snprintf(buf,sizeof(buf),lngtxt(547),
						    ircnick,irchost,ircnick,irchost,
						    irccommand,ircto,irccontent);
		if(user(rc)->instate==STD_CONN && user(rc)->parent==0 && user(rc)->sysmsg==1)
		    writesock(user(rc)->insock,buf);						    
#endif	
		ap_snprintf(irccontent,sizeof(irccontent),"%s",sic);
	    }
	    th=th->next;
	}	
	return 0x0;
    }
    pcontext;
    if (ifcommand("BWHO"))
    {
	th=usernode;
	while (th!=NULL) {
	    rc=th->uid;last=0;
	    if (user(rc)->instate!=STD_NOUSE)
	    {
	       if (user(rc)->parent != 0) l='^'; else { l='*';last=1; }
	       if (user(rc)->sysmsg == 0) l='+';
	       if (*user(rc)->host==0) l=' '; else last=0;
	       if(last==1)
      	           ap_snprintf(ircbuf,sizeof(ircbuf),lngtxt(548),me,ircnick,irchost,me,l,user(rc)->login,user(rc)->nick,user(rc)->network,user(rc)->server,user(rc)->user,user(rc)->last);
	       else	 
      	           ap_snprintf(ircbuf,sizeof(ircbuf),lngtxt(549),me,ircnick,irchost,me,l,user(rc)->login,user(rc)->nick,user(rc)->network,user(rc)->server,user(rc)->user);
	       broadcast(0);						    
	    }
	    th=th->next;
	}
	return 0x0;	
    }
    pcontext;
    if (ifcommand(lngtxt(550)))
    {
	lh=linknode;	
	while (lh!=NULL)
	{	
	    rc=lh->uid;
	    l=' ';
	    if (datalink(rc)->type!=0)
	    {
		if (datalink(rc)->type==LI_LINK) 
		{
		    pt=o;
		    if (datalink(rc)->outstate==STD_CONN) l='*';
		}
		if (datalink(rc)->type==LI_ALLOW) 
		{
		    if (datalink(rc)->instate==STD_CONN) l='*';
		    pt=i;
		}
		if (datalink(rc)->type==LI_RELAY) { pt=r; l='*';}
		ap_snprintf(ircbuf,sizeof(ircbuf),lngtxt(551),me,ircnick,irchost,me,l,rc,pt,datalink(rc)->iam,datalink(rc)->host,datalink(rc)->port); 
		broadcast(0);
	    }    
	    lh=lh->next;
	}
	return 0x0;
    }
    pcontext;
#ifdef PARTYCHANNEL
    if (ifcommand(lngtxt(552)))
    {
	strmncpy(partytopic,irccontent,sizeof(partytopic));
	th=usernode;
	while (th!=NULL) {
	    rc=th->uid;
	    if (user(rc)->instate==STD_CONN && user(rc)->parent==0)
	    {
	       ap_snprintf(buf1,sizeof(buf1),"%s%s%s",lngtxt(553),PARTYCHAN,lngtxt(554));
  	       ssnprintf(user(rc)->insock,buf1,
	                       ircnick,irchost,ircnick,irchost,irccontent);
	    }
	    th=th->next;
	}
    }
#endif
#ifdef INTNET
    if (ifcommand(lngtxt(555)))
    {
	pt=strchr(ircbuf,'\r');
	if(pt==NULL) pt=strchr(ircbuf,'\n');
	if(pt!=NULL) *pt=0;
	strmncpy(ircbuf,rtrim(irccontent),sizeof(ircbuf));
	internalinbound(0,nlink);
    }
#endif
    pcontext;
    return 0x0;
}
コード例 #7
0
ファイル: socket.c プロジェクト: Shirling-VT/VTRST3.5
int processsocket(int sock,int inpipe) {

    fd_set fdset; /* selected file descriptors */
    int poll,i;

    struct timeval tv;

    sigset_t set;
    struct sigaction act;

    sigemptyset(&set);
    sigaddset(&set,SIGUSR1);

    act.sa_flags=0;
    act.sa_mask=set;
    act.sa_handler=trapreset;
    sigaction(SIGUSR1,&act,NULL);

    signal(SIGPIPE,SIG_IGN);

    listen(sock,5);

    tv.tv_sec=0;
    tv.tv_usec=0;

    poll=0;
    runloop=1;
    do {

        FD_ZERO(&fdset);
        FD_SET(inpipe,&fdset);
        if (poll==0) {
            if (pollsock(sock,NULL,&fdset) !=0) continue;
        } else pollsock(sock,&tv,&fdset);

        /* open any new connections if possible */

        opensock(sock,&fdset);

        poll=0;

        /* check to see if the root server has sent any data */

        if (FD_ISSET(inpipe,&fdset)) {
            int size;
            size=read(inpipe,mbuf,BUF_SIZE);
            if (size==0) break;

            /* log the time */

            logtime(timefname,size);
            writeraw(mbuf,size);
        }


        /* send the data to the clients */

        if (writesock() !=0) poll=1;

        /* read back any data from the clients */

        readsock(&fdset,tmpbuf,BUF_SIZE);

        /* decode the buffers here */

    } while(runloop);

    /* close all the clients down */

    for (i=0; i<msgmax; i++) {
        if (client[i].sock !=0) close(client[i].sock);
    }
    close(sock);
    return -1;
}
コード例 #8
0
int translatedpart4(int uid)
{
    char *ept,*pt;
    struct translatet *th;
    struct socketnodes *lkm;
    pcontext;
    th=gettranslate(uid);
    pcontext;
    if(th==NULL)
	return 0x0;
    lkm=getpsocketbysock(th->sock);
    if(lkm==NULL)
    {
	erasetranslate(uid);
	return 0x0;
    }
    pcontext;
    ept=strstr(ircbuf,lngtxt(871));
    if(ept==NULL)
    {
	ept=strstr(ircbuf,"<p>");
    }
    if(ept!=NULL)
    {
	ept=strstr(th->translatedtext,lngtxt(872));
	if(ept!=NULL)
	{
	    ept=strchr(th->translatedtext,':');
	    if(ept==th->translatedtext) ept=strchr(ept+1,':');
	    if(ept!=NULL)
	    {
		*ept=0;
		th->translatedtext=strmcat(th->translatedtext,lngtxt(873));
	    }
	}
	ept=strstr(th->translatedtext,"<P>");
	if(ept!=NULL)
	{ 
	    *ept=0;
	}
	th->translatedtext=strmcat(th->translatedtext,"\r\n");
	if(th->direction==TR_TO)
	{
	    if(user(th->usern)->outstate==STD_CONN)
	    {
		writesock(user(th->usern)->outsock,th->translatedtext);
		if(user(th->usern)->instate>STD_NOCON)
		{
		    pt=strchr(th->translatedtext,':');
		    if(pt!=NULL)
		    {
			if(strchr("#!&+",*th->dest)!=NULL)
			{
			    ssnprintf(user(th->usern)->insock,lngtxt(874),user(th->usern)->nick,user(th->usern)->login,user(th->usern)->host,th->dest,pt);
			} else {
			    ssnprintf(user(th->usern)->insock,lngtxt(875),th->dest,user(th->usern)->nick,pt);
			}
		    }
		}
	    }
	} else {
	    if(user(th->usern)->instate>STD_NOCON)
	    {
		writesock(user(th->usern)->insock,th->translatedtext);
	    }
	}
	erasetranslate(uid); /* job done, socket gone */
    } else {    
	ept=nobreak(ircbuf);
	pt=strstr(ept,"<textarea");
	if(pt!=NULL)
	{
	    pt=strchr(pt,'>');
	    if(pt!=NULL)
	    {
		ept=pt+1;
	    }
	}
	while(*ept==' ' || *ept==9) ept++;
	if(*ept)
	{
	    th->translatedtext=strmcat(th->translatedtext,ept);
	    th->translatedtext=strmcat(th->translatedtext," ");
	}
    }
    return 0x0;
}