예제 #1
0
파일: tcpinp.c 프로젝트: m3y54m/32bitmicro
/*------------------------------------------------------------------------
 *  tcpinp  -  handle TCP segment coming in from IP
 *------------------------------------------------------------------------
 */
PROCESS
tcpinp(void)
{
	struct	ep	*pep;
	struct	ip	*pip;
	struct	tcp	*ptcp;
	struct	tcb	*ptcb;

	tcps_iport = pcreate(TCPQLEN);
	signal(Net.sema);
	while (TRUE) {
		pep = (struct ep *)preceive(tcps_iport);
		if ((int)pep == SYSERR)
			break;
		pip = (struct ip *)pep->ep_data;
		if (tcpcksum(pep, pip->ip_len - IP_HLEN(pip))) {
			++TcpInErrs;
			freebuf(pep);
			continue;
		}
		ptcp = (struct tcp *)pip->ip_data;
		tcpnet2h(ptcp); /* convert all fields to host order */
		pep->ep_order |= EPO_TCP;
		ptcb = tcpdemux(pep);
		if (ptcb == 0) {
			++TcpInErrs;
			tcpreset(pep);
			freebuf(pep);
			continue;
		}
		if (!tcpok(ptcb, pep))
			tcpackit(ptcb, pep);
		else {
			tcpopts(ptcb, pep);
			tcpswitch[ptcb->tcb_state](ptcb, pep);
		}
		if (ptcb->tcb_state != TCPS_FREE)
			signal(ptcb->tcb_mutex);
		freebuf(pep);
	}
}
예제 #2
0
파일: lsr_in.c 프로젝트: m3y54m/32bitmicro
/*------------------------------------------------------------------------
 *  lsr_in - handle a received link state request packet
 *------------------------------------------------------------------------
 */
void
lsr_in(struct ep *pep)
{
	struct ip	*pipout, *pip = (struct ip *)pep->ep_data;
	struct ospf	*poout, *po;
	struct ospf_if	*pif = &ospf_if[pep->ep_ifn];
	struct ospf_nb	*pnb;
	struct ospf_lsr	*plsr;
	struct ospf_lsu	*plsu;
	struct ospf_db	*pdb;
	struct ep	*pepout, *ospflstmpl(struct ospf_if *);
	unsigned	i, nlsr, maxlsapp;

	if (pif->if_state <= IFS_WAITING)
		return;
	pnb = &pif->if_nbtab[1];
	po = (struct ospf *)((char *)pip+IP_HLEN(pip));
	for (i=0; i<MAXNBR; ++i, ++pnb)
		if (pnb->nb_rid == po->ospf_rid)
			break;
	if (i == MAXNBR || pnb->nb_state < NBS_EXCHNG)
		return;
	maxlsapp = (nif[pep->ep_ifn].ni_mtu - IPMHLEN - MINLSULEN);
	maxlsapp /= (LSSHDRLEN + MAXLSDLEN);
	pepout = ospflstmpl(pif);
	if (pepout == 0)
		return;
	pipout = (struct ip *)pepout->ep_data;
	poout = (struct ospf *)pipout->ip_data;
	plsu = (struct ospf_lsu *)poout->ospf_data;
	
	nlsr = (po->ospf_len - MINHDRLEN) / sizeof (struct ospf_lsr);
	plsr = (struct ospf_lsr *)po->ospf_data;
	for (i=0; i<nlsr; ++i, ++plsr) {
		pdb = db_lookup(pif->if_area, plsr->lsr_type,
			plsr->lsr_lsid);
		if (pdb == 0) {
			freebuf(pepout);
			nb_mismatch(pif, pnb);
			return;
		}
		if (plsu->lsu_nads >= maxlsapp) {
			lsa_send(pif, pip->ip_src, pepout);
			if (!(pepout = ospflstmpl(pif)))
				return;
			pipout = (struct ip *)pepout->ep_data;
			poout = (struct ospf *)pipout->ip_data;
			plsu = (struct ospf_lsu *)poout->ospf_data;
		}
		lsa_add(pif, pepout, pdb);
	}
	lsa_send(pif, pip->ip_src, pepout);
}
예제 #3
0
파일: run.c 프로젝트: 8l/cmm
static void
sched(void)
{
	char *flags;
	Job *j;
	Bufblock *buf;
	int slot;
	Node *n;
	Envy *e;

	if(jobs == 0){
		usage();
		return;
	}
	j = jobs;
	jobs = j->next;
	if(DEBUG(D_EXEC))
		printf("firing up job for target %s\n", wtos(j->t, ' '));
	slot = nextslot();
	events[slot].job = j;
	buf = newbuf();
	e = buildenv(j, slot);
	shprint(j->r->recipe, e, buf);
	if(!tflag && (nflag || !(j->r->attr&QUIET)))
		Bwrite(&bout, buf->start, (long)strlen(buf->start));
	freebuf(buf);
	if(nflag||tflag){
		for(n = j->n; n; n = n->next){
			if(tflag){
				if(!(n->flags&VIRTUAL))
					touch(n->name);
				else if(explain)
					Bprint(&bout, "no touch of virtual '%s'\n", n->name);
			}
			n->time = time((long *)0);
			MADESET(n, MADE);
		}
	} else {
		if(DEBUG(D_EXEC))
			printf("recipe='%s'", j->r->recipe);/**/
		Bflush(&bout);
		if(j->r->attr&NOMINUSE)
			flags = 0;
		else
			flags = "-e";
		events[slot].pid = execsh(flags, j->r->recipe, 0, e);
		usage();
		nrunning++;
		if(DEBUG(D_EXEC))
			printf("pid for target %s = %d\n", wtos(j->t, ' '), events[slot].pid);
	}
}
예제 #4
0
파일: cg_func.c 프로젝트: e2bsq/Symphony
int cg_send_cut(cut_data *new_cut, int *num_cuts, int *alloc_cuts,
		cut_data ***cuts)
{
#ifdef COMPILE_IN_CG

   int i;
   cut_data *tmp_cut;

   for (i = 0; i < *num_cuts; i++){
      if (new_cut->type != (*cuts)[i]->type ||
	  new_cut->size != (*cuts)[i]->size ||
	  new_cut->rhs != (*cuts)[i]->rhs){
	 continue;
      }
      if (!new_cut->coef){
	 return(0);
      }
      if (memcmp(new_cut->coef, (*cuts)[i]->coef,
		 new_cut->size) == 0){
	 return(0);
      }
   }
   if (new_cut->name != CUT__DO_NOT_SEND_TO_CP)
      new_cut->name = CUT__SEND_TO_CP;
   tmp_cut = (cut_data *) malloc (sizeof(cut_data));
   memcpy((char *)tmp_cut, (char *)new_cut, sizeof(cut_data));
   if (new_cut->size >0){
      tmp_cut->coef = (char *) malloc (new_cut->size * sizeof(char));
      memcpy((char *)tmp_cut->coef, (char *)new_cut->coef,
	     new_cut->size * sizeof(char));
   }
   REALLOC((*cuts), cut_data *, (*alloc_cuts), (*num_cuts + 1), BB_BUNCH);
   (*cuts)[(*num_cuts)++] = tmp_cut;
   
#else

   int s_bufid;
   
   if (new_cut->name != CUT__DO_NOT_SEND_TO_CP)
      new_cut->name = CUT__SEND_TO_CP;
   s_bufid = init_send(DataInPlace);
   pack_cut(new_cut);
   send_msg(p->cur_sol.lp, PACKED_CUT);
   freebuf(s_bufid);
   
#endif

   return(1);
}
예제 #5
0
파일: ibget.c 프로젝트: dancrossnyc/xinu68k
//------------------------------------------------------------------------
//  ibget  --  get an iblock from disk given its number
//------------------------------------------------------------------------
void
ibget(int diskdev, IBADDR inum, struct iblk *loc)
{
	char *from, *to;
	int i;
	char *buff;

	buff = getbuf(dskdbp);
	read(diskdev, buff, ibtodb(inum));
	from = buff + ibdisp(inum);
	to = (char *)loc;
	for (i = 0; i < sizeof(struct iblk); i++)
		*to++ = *from++;
	freebuf(buff);
}
예제 #6
0
파일: stdio.c 프로젝트: HarryR/sanos
static int close_file(FILE *stream) {
  int rc = EOF;

  if (stream->flag & _IOSTR) {
    stream->flag = 0;
    return EOF;
  }

  rc = fflush(stream);
  freebuf(stream);

  if (close(fileno(stream)) < 0) rc = EOF;

  return rc;
}
예제 #7
0
파일: singlesort.c 프로젝트: jtf/parsort
int main(int argc, char *argv[])
{
  struct buffer b;
  struct buffer tmpbuf;

  struct timespec t_0, t_1, t_2;

  int size = 1024*1024*1024;

  clock_gettime(CLOCK_MONOTONIC, &t_0);

  if ( allocbuf(&b, size) && allocbuf(&tmpbuf, size) )
    {


      randbuf(&b);

      clock_gettime(CLOCK_MONOTONIC, &t_1);

      mergesort(&b, &tmpbuf, 0);
//      quicksort(&b);


      freebuf(&tmpbuf);
      freebuf(&b);

      clock_gettime(CLOCK_MONOTONIC, &t_2);

      printf ("Gesamtzeit: %llu \tRandomzeit: %llu\tSortierzeit: %llu\n",
          timediff(&t_0, &t_2), timediff(&t_0, &t_1), timediff(&t_1, &t_2));
    }
  else
    {
      printf("Fehler beim Allozieren der Puffer\n");
    }
}
예제 #8
0
Word *
varsub(char **s)
{
	Bufblock *b;
	Word *w;

	if(**s == '{')		/* either ${name} or ${name: A%B==C%D}*/
		return expandvar(s);

	b = varname(s);
	if(b == 0)
		return 0;

	w = varmatch(b->start, s);
	freebuf(b);
	return w;
}
예제 #9
0
/*------------------------------------------------------------------------
 * udp_release  -  Release a previously-registered UDP slot
 *------------------------------------------------------------------------
 */
status	udp_release (
	 uid32	slot			/* Table slot to release	*/
	)
{
	intmask	mask;			/* Saved interrupt mask		*/
	struct	udpentry *udptr;	/* Pointer to udptab entry	*/
	struct	netpacket *pkt;		/* pointer to packet being read	*/

	/* Ensure only one process can access the UDP table at a time	*/

	mask = disable();

	/* Verify that the slot is valid */

	if ( (slot < 0) || (slot >= UDP_SLOTS) ) {
		restore(mask);
		return SYSERR;
	}

	/* Get pointer to table entry */

	udptr = &udptab[slot];

	/* Verify that the slot has been registered and is valid */

	if (udptr->udstate == UDP_FREE) {
		restore(mask);
		return SYSERR;
	}

	/* Defer rescheduling to prevent freebuf from switching context	*/

	resched_cntl(DEFER_START);
	while (udptr->udcount > 0) {
		pkt = udptr->udqueue[udptr->udhead++];
		if (udptr->udhead >= UDP_QSIZ) {
			udptr->udhead = 0;
		}
		freebuf((char *)pkt);
		udptr->udcount--;
	}
	udptr->udstate = UDP_FREE;
	resched_cntl(DEFER_STOP);
	restore(mask);
	return OK;
}
예제 #10
0
/*------------------------------------------------------------------------
 *  ip_in - IP input function
 *------------------------------------------------------------------------
 */
int
ip_in(struct netif *pni, struct ep *pep)
{
    struct	ip	*pip = (struct ip *)pep->ep_data;

    IpInReceives++;//count amount of times it receives an ip packet

    //put it in the queue

    if (enq(pni->ni_ipinq, pep, pip->ip_tos & IP_PREC) < 0) {//if what is returned is negative then discard
        IpInDiscards++;
        freebuf(pep);
    }

    send(ippid, (pni->&nif[0]));
    return OK;
}
예제 #11
0
파일: ethRead.c 프로젝트: BridgeNY/purdue
/*------------------------------------------------------------------------
 * ethRead - read a packet from an Ethernet device
 *------------------------------------------------------------------------
 */
devcall	ethRead (
	 struct	dentry	*devptr,	/* entry in device switch table	*/
	 void	*buf,			/* buffer to hold packet	*/
	 uint32	len			/* length of buffer		*/
	)
{
	struct	ether	*ethptr;	/* ptr to entry in ethertab	*/
	struct	ethPktBuffer	*pkt;	/* ptr to a packet		*/
	uint32	length;			/* packet length		*/

	ethptr = &ethertab[devptr->dvminor];

	if (ETH_STATE_UP != ethptr->state) {
		return SYSERR; /* interface is down */
	}

	/* Make sure user's buffer is large enough to store at least	*/
	/*   the header of a packet					*/

	if (len < ETH_HDR_LEN) {
		return SYSERR;
	}

	/* Wait for a packet to arrive */

	wait(ethptr->isema);

	/* Pick up packet */

	pkt = ethptr->in[ethptr->istart];
	ethptr->in[ethptr->istart] = NULL;
	ethptr->istart = (ethptr->istart + 1) % ETH_IBUFSIZ;
	ethptr->icount--;

	if (pkt == NULL) {
		return 0;
	}

	length = pkt->length;
	memcpy(buf, (byte *)(((uint32)pkt->buf) | KSEG1_BASE), length);
	freebuf((char *)pkt);

	return length;
}
예제 #12
0
/*------------------------------------------------------------------------
 * icmp_release  -  Release a previously-registered ICMP icmpid
 *------------------------------------------------------------------------
 */
status	icmp_release (
	 int32	icmpid			/* Slot in icmptab to release	*/
	)
{
	intmask	mask;			/* Saved interrupt mask		*/
	struct	icmpentry *icmptr;	/* Pointer to icmptab entry	*/
	struct	netpacket *pkt;		/* Pointer to packet		*/

	mask = disable();

	/* Check arg and insure entry in table is in use */

	if ( (icmpid < 0) || (icmpid >= ICMP_SLOTS) ) {
		restore(mask);
		return SYSERR;
	}
	icmptr = &icmptab[icmpid];
	if (icmptr->icstate != ICMP_USED) {
		restore(mask);
		return SYSERR;
	}

	/* Remove each packet from the queue and free the buffer */

	resched_cntl(DEFER_START);
	while (icmptr->iccount > 0) {
		pkt = icmptr->icqueue[icmptr->ichead++];
		if (icmptr->ichead >= ICMP_SLOTS) {
			icmptr->ichead = 0;

		}
		freebuf((char *)pkt);
		icmptr->iccount--;
	}

	/* Mark the entry free */

	icmptr->icstate = ICMP_FREE;
	resched_cntl(DEFER_STOP);
	restore(mask);
	return OK;
}
예제 #13
0
//------------------------------------------------------------------------
//  dsread  --  read a block from a disk device
//------------------------------------------------------------------------
int
dsread(struct devsw *devptr, void *buff, DBADDR block)
{
	struct dreq *drptr;
	int stat;
	int ps;

	ps = disable();
	drptr = (struct dreq *)getbuf(dskrbp);
	drptr->drdba = block;
	drptr->drpid = currpid;
	drptr->drbuff = buff;
	drptr->drop = DREAD;
	if ((stat = dskenq(drptr, (struct dsblk *)devptr->iobuf)) == DONQ) {
		suspend(currpid);
		stat = drptr->drstat;
	}
	freebuf(drptr);
	restore(ps);
	return stat;
}
예제 #14
0
/*------------------------------------------------------------------------
 * txPackets - handler for transmitter interrupts
 *------------------------------------------------------------------------
 */
void	txPackets (
	 struct	ether *ethptr,		/* ptr to control block		*/
	 struct ag71xx *nicptr		/* ptr to device CSRs		*/
	)
{
	struct	dmaDescriptor *dmaptr;
	struct	ethPktBuffer **epb = NULL;
	struct	ethPktBuffer *pkt = NULL;
	uint32	head;

	if (ethptr->txHead == ethptr->txTail) {
		nicptr->txStatus = TX_STAT_SENT;
		return;
	}

	/* While packets remain to be transmitted */

	while (ethptr->txHead != ethptr->txTail) {
		head = ethptr->txHead % ETH_TX_RING_ENTRIES;
		dmaptr = &ethptr->txRing[head];
		if (!(dmaptr->control & ETH_DESC_CTRL_EMPTY)) {
			break;
		}

		epb = &ethptr->txBufs[head];

		/* Clear the Tx interrupt */

		nicptr->txStatus = TX_STAT_SENT;

		ethptr->txHead++;
		pkt = *epb;
		if (NULL == pkt) {
			continue;
		}
		freebuf((void *)((bpid32)pkt & (PMEM_MASK | KSEG0_BASE)));
		*epb = NULL;
	}
	return;
}
예제 #15
0
파일: virtfile.c 프로젝트: pgul/lgate
int virt_putc(char c, VIRT_FILE *f)
{
  if (f==NULL)
  { errno=EBADF;
    return EOF;
  }
#ifdef __MSDOS__
  if (f->file == NULL)
#else
  if (f->buf == NULL)
#endif
  { errno=EBADF;
    return EOF;
  }
  if (f->offbody && c=='\n')
    f->lines++;
  if (f->offbody==0 && f->waslf)
    if (c=='\n')
      f->offbody=f->curpos;
  f->waslf = (c=='\n');
  msgsize++;
#ifdef __MSDOS__
  f->curpos++;
  return putc(c, f->file);
#else
  if (f->curpos == f->bufsize)
  { void *newbuf;
    if ((newbuf = bufrealloc(f->buf, f->bufsize+=BUFSIZE)) == NULL)
    { errno=ENOMEM;
      freebuf(f->buf);
      f->buf = NULL;
      return EOF;
    }
    f->buf=newbuf;
  }
  bufcopy(f->buf, f->curpos++, &c, 1);
  return 1;
#endif
}
//! The purpose of this function to provide a convenient way of generating formatted
//! STL strings inline. This is especially useful when throwing exceptions that take
//! a std::string for a message. The length of the formatted output string is limited
//! only by memory. Memory temporarily allocated for the output string is disposed of
//! before returning.
//!
//! Example usage:
//! \code
//!		throw std::runtime_error(format_string("error on line %d", line));
//! \endcode
//!
//! \param fmt Format string using printf-style format markers.
//! \return An STL string object of the formatted output.
std::string format_string(const char *fmt, ...)
{
    char *buf = 0;
    va_list vargs;
    va_start(vargs, fmt);
    int result = -1;
#if WIN32
    buf = (char *)malloc(WIN32_FMT_BUF_LEN);
    if (buf)
    {
        result = _vsnprintf(buf, WIN32_FMT_BUF_LEN, fmt, vargs);
    }
#else  // WIN32
    result = vasprintf(&buf, fmt, vargs);
#endif // WIN32
    va_end(vargs);
    if (result != -1 && buf)
    {
        free_ptr<char *> freebuf(buf);
        return std::string(buf);
    }
    return "";
}
예제 #17
0
void wait_for_you_can_die(dg_prob *dgp, FILE *write_to)
{
   int bufid, s_bufid, bytes, msgtag, sender;

   FREE(dgp->windows);
   /* invoke the Igd_QuitAll function */
   spprint(write_to, "Igd_QuitAll\n");

   if (dgp->waiting_to_die == 2 * TRUE)
      exit(0);

   while (TRUE){
      receive_msg(ANYONE, ANYTHING);
      bufinfo(bufid, &bytes, &msgtag, &sender);
      if (msgtag != CTOI_YOU_CAN_DIE){
	 s_bufid = init_send(DataInPlace);
	 send_msg(sender, ITOC_APPLICATION_KILLED);
	 freebuf(s_bufid);
      }else{
	 exit(0);
      }
   }
}
예제 #18
0
파일: stdio.c 프로젝트: HarryR/sanos
int setvbuf(FILE *stream, char *buffer, int type, size_t size) {
  fflush(stream);
  freebuf(stream);

  stream->flag &= ~(_IOOWNBUF | _IOEXTBUF | _IONBF);

  if (type & _IONBF) {
    stream->flag |= _IONBF;
    buffer = (char *) &stream->charbuf;
    size = 1;
  } else if (buffer == NULL) {
    if ((buffer = malloc(size)) == NULL ) return -1;
    stream->flag |= _IOOWNBUF;
  } else {
    stream->flag |= _IOEXTBUF;
  }

  stream->bufsiz = size;
  stream->ptr = stream->base = buffer;
  stream->cnt = 0;

  return 0;
}
예제 #19
0
파일: udp.c 프로젝트: eerpini/Xinu-RPL
/*------------------------------------------------------------------------
 * udp_release - release a previously-registered remote IP, remote
 *			port, and local port (exact match required)
 *------------------------------------------------------------------------
 */
status	udp_release (
    uint32	remip,			/* remote IP address or zero	*/
    uint16	remport,		/* remote UDP protocol port	*/
    uint16	locport			/* local UDP protocol port	*/
)
{
    int32	i;			/* index into udptab		*/
    struct	udpentry *udptr;	/* pointer to udptab entry	*/
    struct	eth_packet *pkt;		/* ptr to packet being read	*/

    for (i=0; i<UDP_SLOTS; i++) {
        udptr = &udptab[i];
        if (udptr->udstate != UDP_USED) {
            continue;
        }
        if ((remport == udptr->udremport) &&
                (locport == udptr->udlocport) &&
                (remip   == udptr->udremip  ) ) {

            /* Entry in table matches */

            sched_cntl(DEFER_START);
            while (udptr->udcount > 0) {
                pkt = udptr->udqueue[udptr->udhead++];
                if (udptr->udhead >= UDP_SLOTS) {
                    udptr->udhead = 0;
                }
                freebuf((char *)pkt);
                udptr->udcount--;
            }
            udptr->udstate = UDP_FREE;
            sched_cntl(DEFER_STOP);
            return OK;
        }
    }
    return SYSERR;
}
예제 #20
0
파일: ether.c 프로젝트: npe9/harvey
static void
fsclunk(Usbfs *fs, Fid *fid)
{
	int qt;
	int64_t qid;
	Buf *bp;
	Conn *c;
	Ether *e;

	e = fs->aux;
	qid = fid->qid.path & ~fs->qid;
	qt = qtype(qid);
	switch(qt){
	case Qndata:
	case Qnctl:
	case Qnifstats:
	case Qnstats:
	case Qntype:
		if(fid->omode != ONONE){
			c = getconn(e, qnum(qid), 0);
			if(c == nil)
				sysfatal("usb: ether: fsopen bug");
			if(decref(c) == 0){
				while((bp = nbrecvp(c->rc)) != nil)
					freebuf(e, bp);
				qlock(e);
				if(c->prom != 0)
					if(decref(&e->prom) == 0)
						prom(e, 0);
				c->prom = c->type = 0;
				qunlock(e);
			}
		}
		break;
	}
	etherdump(e);
}
예제 #21
0
파일: devio.c 프로젝트: davidgiven/FUZIX
/*
 *	Make an entry in the buffer cache and fill it. If rewrite is
 *	set then we are not keeping any of the old data but overwriting
 *	it all.
 *
 *	Hands back either a locked buffer, or NULL on an error.
 */
bufptr bread(uint16_t dev, blkno_t blk, bool rewrite)
{
	regptr bufptr bp;

	if ((bp = bfind(dev, blk)) == NULL) {
		bp = freebuf();
		bp->bf_dev = dev;
		bp->bf_blk = blk;

		/* If rewrite is set, we are about to write over the entire block,
		   so we don't need the previous contents */
		if (!rewrite) {
			if (bdread(bp) != BLKSIZE) {
				udata.u_error = EIO;
				/* Don't cache the failure */
				bp->bf_dev = NO_DEVICE;
				bp->bf_dirty = false;
				bunlock(bp);
				return (NULL);
			}
		}
	}
	return bp;
}
예제 #22
0
int init_draw_graph_u(sym_environment *env)
{
   if (env->par.do_draw_graph){ /*start up the graphics window*/
      int s_bufid;
      if (env->par.dg_machine_set){
	 spawn(env->par.dg_exe, (char **)NULL, env->par.dg_debug | TaskHost,
	       env->par.dg_machine, 1, &env->dg_tid);
      }else{
	 spawn(env->par.dg_exe, (char **)NULL, env->par.dg_debug, (char *)NULL, 1,
	       &env->dg_tid);
      }
      s_bufid = init_send(DataInPlace);
      send_char_array((char *)&env->par.dg_par, sizeof(dg_params));
      send_msg(env->dg_tid, DG_DATA);
      freebuf(s_bufid);

#ifdef USE_SYM_APPLICATION
      if (env->dg_tid)
	 CALL_USER_FUNCTION( user_init_draw_graph(env->user, env->dg_tid) );
#endif
   }

   return(FUNCTION_TERMINATED_NORMALLY);
}
예제 #23
0
파일: udp.c 프로젝트: eerpini/Xinu-RPL
/*------------------------------------------------------------------------
 * udp_recvaddr - receive a UDP packet and record the sender's address
 *------------------------------------------------------------------------
 */
int32	udp_recvaddr (
    uint32	*remip,			/* loc to record remote IP addr.*/
    uint16	*remport,		/* loc to record remote port	*/
    uint16	locport,		/* local UDP protocol port	*/
    char   *buff,			/* buffer to hold UDP data	*/
    int32	len,			/* length of buffer		*/
    uint32	timeout			/* read timeout in msec		*/
)
{
    intmask	mask;			/* saved interrupt mask		*/
    int32	i;			/* index into udptab		*/
    struct	udpentry *udptr;	/* pointer to udptab entry	*/
    umsg32	msg;			/* message from recvtime()	*/
    struct	eth_packet *pkt;		/* ptr to packet being read	*/
    struct  ipv4_packet *ippkt = NULL;
    struct  udp_packet * udppkt = NULL;
    int32	msglen;			/* length of UDP data in packet	*/
    char	*udataptr;		/* pointer to UDP data		*/

    /* Insure only one process access UDP table at a time */

    mask = disable();

    for (i=0; i<UDP_SLOTS; i++) {
        udptr = &udptab[i];
        if ( (udptr->udremip == 0 ) &&
                (locport == udptr->udlocport) ) {

            /* Entry in table matches request */
            break;
        }
    }

    if (i >= UDP_SLOTS) {
        restore(mask);
        return SYSERR;
    }

    if (udptr->udcount == 0) {	/* no packet is waiting */
        udptr->udstate = UDP_RECV;
        udptr->udpid = currpid;
        msg = recvclr();
        msg = recvtime(timeout);	/* wait for packet */
        udptr->udstate = UDP_USED;
        if (msg == TIMEOUT) {
            restore(mask);
            return TIMEOUT;
        } else if (msg != OK) {
            restore(mask);
            return SYSERR;
        }
    }

    /* Packet has arrived -- dequeue it */

    pkt = udptr->udqueue[udptr->udhead++];
    ippkt = (struct ipv4_packet *)(pkt->net_ethdata);
    udppkt = (struct udp_packet *)(ippkt->net_ipdata);
    if (udptr->udhead >= UDP_SLOTS) {
        udptr->udhead = 0;
    }
    udptr->udcount--;

    /* Record sender's IP address and UDP port number */

    *remip = ippkt->net_ipsrc;
    *remport = udppkt->net_udpsport;

    /* Copy UDP data from packet into caller's buffer */

    msglen = udppkt->net_udplen - UDP_HDR_LEN;
    udataptr = (char *)udppkt->net_udpdata;
    for (i=0; i<msglen; i++) {
        if (i >= len) {
            break;
        }
        *buff++ = *udataptr++;
    }
    freebuf((char *)pkt);
    restore(mask);
    return i;
}
예제 #24
0
/*------------------------------------------------------------------------
 * udp_recvaddr  -  Receive a UDP packet and record the sender's address
 *------------------------------------------------------------------------
 */
int32	udp_recvaddr (
	 uid32	slot,			/* Slot in table to use		*/
	 uint32	*remip,			/* Loc for remote IP address	*/
	 uint16	*remport,		/* Loc for remote protocol port	*/
	 char   *buff,			/* Buffer to hold UDP data	*/
	 int32	len,			/* Length of buffer		*/
	 uint32	timeout			/* Read timeout in msec		*/
	)
{
	intmask	mask;			/* Saved interrupt mask		*/
	struct	udpentry *udptr;	/* Pointer to udptab entry	*/
	umsg32	msg;			/* Message from recvtime()	*/
	struct	netpacket *pkt;		/* Pointer to packet being read	*/
	int32	msglen;			/* Length of UDP data in packet	*/
	int32	i;			/* Counts bytes copied		*/
	char	*udataptr;		/* Pointer to UDP data		*/

	/* Ensure only one process can access the UDP table at a time	*/

	mask = disable();

	/* Verify that the slot is valid */

	if ((slot < 0) || (slot >= UDP_SLOTS)) {
		restore(mask);
		return SYSERR;
	}

	/* Get pointer to table entry */

	udptr = &udptab[slot];

	/* Verify that the slot has been registered and is valid */

	if (udptr->udstate != UDP_USED) {
		restore(mask);
		return SYSERR;
	}

	/* Wait for a packet to arrive */

	if (udptr->udcount == 0) {		/* No packet is waiting */
		udptr->udstate = UDP_RECV;
		udptr->udpid = currpid;
		msg = recvclr();
		msg = recvtime(timeout);	/* Wait for a packet	*/
		udptr->udstate = UDP_USED;
		if (msg == TIMEOUT) {
			restore(mask);
			return TIMEOUT;
		} else if (msg != OK) {
			restore(mask);
			return SYSERR;
		}
	}

	/* Packet has arrived -- dequeue it */

	pkt = udptr->udqueue[udptr->udhead++];
	if (udptr->udhead >= UDP_QSIZ) {
		udptr->udhead = 0;
	}

	/* Record sender's IP address and UDP port number */

	*remip = pkt->net_ipsrc;
	*remport = pkt->net_udpsport;

	udptr->udcount--;

	/* Copy UDP data from packet into caller's buffer */

	msglen = pkt->net_udplen - UDP_HDR_LEN;
	udataptr = (char *)pkt->net_udpdata;
	if (len < msglen) {
		msglen = len;
	}
	for (i=0; i<msglen; i++) {
		*buff++ = *udataptr++;
	}
	freebuf((char *)pkt);
	restore(mask);
	return msglen;
}
예제 #25
0
int send_lp_data_u(sym_environment *env, int sender)
{
#if defined(COMPILE_IN_TM) && defined(COMPILE_IN_LP)
   int i;
   tm_prob *tm = env->tm;
   tm->par.max_active_nodes = env->par.tm_par.max_active_nodes;
#ifdef _OPENMP
   omp_set_dynamic(FALSE);
   omp_set_num_threads(tm->par.max_active_nodes);
#else
   tm->par.max_active_nodes = 1;
#endif

   tm->lpp = (lp_prob **) malloc(tm->par.max_active_nodes * sizeof(lp_prob *));

#pragma omp parallel for
   for (i = 0; i < tm->par.max_active_nodes; i ++){
      tm->lpp[i] = (lp_prob *) calloc(1, sizeof(lp_prob));
      tm->lpp[i]->proc_index = i;
      tm->lpp[i]->par = env->par.lp_par;

      if ((tm->lpp[i]->has_ub = env->has_ub)){
	 tm->lpp[i]->ub = env->ub;
      }else{
	 env->ub = - (MAXDOUBLE / 2);
      }
      if (env->par.multi_criteria){
	 if ((tm->lpp[i]->has_mc_ub = env->has_mc_ub)){
	    tm->lpp[i]->mc_ub = env->mc_ub;
	    tm->lpp[i]->obj[0] = env->obj[0];
	    tm->lpp[i]->obj[1] = env->obj[1];
	 }else{
	    env->mc_ub = - (MAXDOUBLE / 2);
	 }
	 tm->lpp[i]->utopia[0] = env->utopia[0];
	 tm->lpp[i]->utopia[1] = env->utopia[1];
      }
      tm->lpp[i]->draw_graph = env->dg_tid;
      tm->lpp[i]->base = *(env->base);
      tm->lpp[i]->mip = env->mip;

#ifdef USE_SYM_APPLICATION
      CALL_USER_FUNCTION( user_send_lp_data(env->user, &(tm->lpp[i]->user)) );
#endif
   }
#else   
   int s_bufid;

   s_bufid = init_send(DataInPlace);
   send_char_array((char *)(&env->par.lp_par), sizeof(lp_params));
   send_char_array(&env->has_ub, 1);
   if (env->has_ub)
      send_dbl_array(&env->ub, 1);
   if (env->par.multi_crtieria){
      send_char_array(&env->has_mc_ub, 1);
      if (env->has_mc_ub){
	 send_dbl_array(&env->mc_ub, 1);
	 send_dbl_array(env->obj, 2);
      }
      send_dbl_array(env->utopia, 2);
   }
   send_int_array(&env->dg_tid, 1);
   send_int_array(&env->base->varnum, 1);
   if (env->base->varnum){
      send_int_array(env->base->userind, env->base->varnum);
   }
   send_int_array(&env->base->cutnum, 1);
   if (env->mip){
      MIPdesc *mip = env->mip;
      char has_desc = TRUE;
      char has_colnames = FALSE;
      send_char_array(&has_desc, 1);
      send_int_array(&(mip->m), 1);
      send_int_array(&(mip->n), 1);
      send_int_array(&(mip->nz), 1);
      send_char_array(&(mip->obj_sense), 1);
      send_dbl_array(&(mip->obj_offset), 1);
      send_int_array(mip->matbeg, mip->n);
      send_int_array(mip->matind, mip->nz);
      send_dbl_array(mip->matval, mip->nz);
      send_dbl_array(mip->obj, mip->n);
      if (env->par.multi_criteria){
	 send_dbl_array(mip->obj, mip->n);
	 send_dbl_array(mip->obj2, mip->n);
      }
      send_dbl_array(mip->rhs, mip->m);
      send_char_array(mip->sense, mip->m);
      send_dbl_array(mip->rngval, mip->m);
      send_dbl_array(mip->ub, mip->n);
      send_dbl_array(mip->lb, mip->n);
      send_char_array(mip->is_int, mip->n);
      if (mip->colname){
	 int i;
	 has_colnames = TRUE;
	 send_char_array(&has_colnames, 1);
	 for (i = 0; i < mip->n; i++){
	    send_char_array(mip->colname[i], 8);
	 }
      }else{
	 send_char_array(&has_colnames, 1);
      }	 
   }else{
      char has_desc = FALSE;
      send_char_array(&has_desc, 1);
   }
#ifdef USE_SYM_APPLICATION
   CALL_USER_FUNCTION( user_send_lp_data(env->user, NULL) );
#endif
   send_msg(sender, LP_DATA);
   freebuf(s_bufid);
#endif

   return(FUNCTION_TERMINATED_NORMALLY);
}
예제 #26
0
/*------------------------------------------------------------------------
 * icmp_in  -  Handle an incoming icmp packet
 *------------------------------------------------------------------------
 */
void	icmp_in(
	  struct netpacket *pkt		/* Pointer to incoming packet	*/
	)
{
	intmask	mask;			/* Saved interrupt mask		*/
	int32	slot;			/* Slot in ICMP table		*/
	struct	icmpentry *icmptr;	/* Pointer to icmptab entry	*/
	struct	netpacket *replypkt;	/* Pointer to reply packet	*/

	mask = disable();

	/* Discard all ICMP messages except ping */

	if ( (pkt->net_ictype != ICMP_ECHOREPLY) &&
	     (pkt->net_ictype != ICMP_ECHOREQST)  )	{
		freebuf((char *)pkt);
		restore(mask);
		return;
	}

	/* Handle Echo Request message */

	if (pkt->net_ictype == ICMP_ECHOREQST) {

		/* Send echo reply message */

		replypkt = icmp_mkpkt(pkt->net_ipsrc,ICMP_ECHOREPLY,
				pkt->net_icident, pkt->net_icseq,
				(char *) &pkt->net_icdata,
				pkt->net_iplen-IP_HDR_LEN-ICMP_HDR_LEN);
		if ((int32)replypkt != SYSERR) {
			ip_enqueue(replypkt);
		}
		freebuf((char *)pkt);
		restore(mask);
		return;
	}

	/* Handle Echo Reply message: verify that ID is valid */

	slot = pkt->net_icident;
	if ( (slot < 0) || (slot >= ICMP_SLOTS) ) {
		freebuf((char *)pkt);
		restore(mask);
		return;
	}

	/* Verify that slot in table is in use and IP address	*/
	/*    in incomming packet matches IP address in table	*/

	icmptr = &icmptab[slot];
	if ( (icmptr->icstate == ICMP_FREE) ||
	     (pkt->net_ipsrc != icmptr->icremip) ) {
		freebuf((char *)pkt);	/* discard packet */
		restore(mask);
		return;
	}

	/* Add packet to queue */

	icmptr->iccount++;
	icmptr->icqueue[icmptr->ictail++] = pkt;
	if (icmptr->ictail >= ICMP_QSIZ) {
		icmptr->ictail = 0;
	}
	if (icmptr->icstate == ICMP_RECV) {
		icmptr->icstate = ICMP_USED;
		send (icmptr->icpid, OK);
	}
	restore(mask);
	return;
}
예제 #27
0
static Word*
subsub(Word *v, char *s, char *end)
{
	int nmid;
	Word *head, *tail, *w, *h;
	Word *a, *b, *c, *d;
	Bufblock *buf;
	char *cp, *enda;

	a = extractpat(s, &cp, "=%&", end);
	b = c = d = 0;
	if(PERCENT(*cp))
		b = extractpat(cp+1, &cp, "=", end);
	if(*cp == '=')
		c = extractpat(cp+1, &cp, "&%", end);
	if(PERCENT(*cp))
		d = stow(cp+1);
	else if(*cp)
		d = stow(cp);

	head = tail = 0;
	buf = newbuf();
	for(; v; v = v->next){
		h = w = 0;
		if(submatch(v->s, a, b, &nmid, &enda)){
			/* enda points to end of A match in source;
			 * nmid = number of chars between end of A and start of B
			 */
			if(c){
				h = w = wdup(c);
				while(w->next)
					w = w->next;
			}
			if(PERCENT(*cp) && nmid > 0){	
				if(w){
					bufcpy(buf, w->s, strlen(w->s));
					bufcpy(buf, enda, nmid);
					insert(buf, 0);
					free(w->s);
					w->s = strdup(buf->start);
				} else {
					bufcpy(buf, enda, nmid);
					insert(buf, 0);
					h = w = newword(buf->start);
				}
				buf->current = buf->start;
			}
			if(d && *d->s){
				if(w){

					bufcpy(buf, w->s, strlen(w->s));
					bufcpy(buf, d->s, strlen(d->s));
					insert(buf, 0);
					free(w->s);
					w->s = strdup(buf->start);
					w->next = wdup(d->next);
					while(w->next)
						w = w->next;
					buf->current = buf->start;
				} else
					h = w = wdup(d);
			}
		}
		if(w == 0)
			h = w = newword(v->s);
	
		if(head == 0)
			head = h;
		else
			tail->next = h;
		tail = w;
	}
	freebuf(buf);
	delword(a);
	delword(b);
	delword(c);
	delword(d);
	return head;
}
예제 #28
0
void
main(int argc, char **argv)
{
	Word *w;
	char *s, *temp;
	char *files[256], **f = files, **ff;
	int sflag = 0;
	int i;
	int tfd = -1;
	Biobuf tb;
	Bufblock *buf;
	Bufblock *whatif;

	/*
	 *  start with a copy of the current environment variables
	 *  instead of sharing them
	 */

	Binit(&bout, 1, OWRITE);
	buf = newbuf();
	whatif = 0;
	USED(argc);
	for(argv++; *argv && (**argv == '-'); argv++)
	{
		bufcpy(buf, argv[0], strlen(argv[0]));
		insert(buf, ' ');
		switch(argv[0][1])
		{
		case 'a':
			aflag = 1;
			break;
		case 'd':
			if(*(s = &argv[0][2]))
				while(*s) switch(*s++)
				{
				case 'p':	debug |= D_PARSE; break;
				case 'g':	debug |= D_GRAPH; break;
				case 'e':	debug |= D_EXEC; break;
				}
			else
				debug = 0xFFFF;
			break;
		case 'e':
			explain = &argv[0][2];
			break;
		case 'f':
			if(*++argv == 0)
				badusage();
			*f++ = *argv;
			bufcpy(buf, argv[0], strlen(argv[0]));
			insert(buf, ' ');
			break;
		case 'i':
			iflag = 1;
			break;
		case 'k':
			kflag = 1;
			break;
		case 'n':
			nflag = 1;
			break;
		case 's':
			sflag = 1;
			break;
		case 't':
			tflag = 1;
			break;
		case 'u':
			uflag = 1;
			break;
		case 'w':
			if(whatif == 0)
				whatif = newbuf();
			else
				insert(whatif, ' ');
			if(argv[0][2])
				bufcpy(whatif, &argv[0][2], strlen(&argv[0][2]));
			else {
				if(*++argv == 0)
					badusage();
				bufcpy(whatif, &argv[0][0], strlen(&argv[0][0]));
			}
			break;
		default:
			badusage();
		}
	}
#ifdef	PROF
	{
		extern etext();
		monitor(main, etext, buf, sizeof buf, 300);
	}
#endif

	if(aflag)
		iflag = 1;
	usage();
	syminit();
	initenv();
	usage();

	/*
		assignment args become null strings
	*/
	temp = 0;
	for(i = 0; argv[i]; i++) if(utfrune(argv[i], '=')){
		bufcpy(buf, argv[i], strlen(argv[i]));
		insert(buf, ' ');
		if(tfd < 0){
			temp = maketmp();
			if(temp == 0) {
				perror("temp file");
				Exit();
			}
			close(create(temp, OWRITE, 0600));
			if((tfd = open(temp, 2)) < 0){
				perror(temp);
				Exit();
			}
			Binit(&tb, tfd, OWRITE);
		}
		Bprint(&tb, "%s\n", argv[i]);
		*argv[i] = 0;
	}
	if(tfd >= 0){
		Bflush(&tb);
		LSEEK(tfd, 0L, 0);
		parse("command line args", tfd, 1);
		remove(temp);
	}

	if (buf->current != buf->start) {
		buf->current--;
		insert(buf, 0);
	}
	symlook("MKFLAGS", S_VAR, (void *) stow(buf->start));
	buf->current = buf->start;
	for(i = 0; argv[i]; i++){
		if(*argv[i] == 0) continue;
		if(i)
			insert(buf, ' ');
		bufcpy(buf, argv[i], strlen(argv[i]));
	}
	insert(buf, 0);
	symlook("MKARGS", S_VAR, (void *) stow(buf->start));
	freebuf(buf);

	if(f == files){
		if(access(MKFILE, 4) == 0)
			parse(MKFILE, open(MKFILE, 0), 0);
	} else
		for(ff = files; ff < f; ff++)
			parse(*ff, open(*ff, 0), 0);
	if(DEBUG(D_PARSE)){
		dumpw("default targets", target1);
		dumpr("rules", rules);
		dumpr("metarules", metarules);
		dumpv("variables");
	}
	if(whatif){
		insert(whatif, 0);
		timeinit(whatif->start);
		freebuf(whatif);
	}
	execinit();
	/* skip assignment args */
	while(*argv && (**argv == 0))
		argv++;

	catchnotes();
	if(*argv == 0){
		if(target1)
			for(w = target1; w; w = w->next)
				mk(w->s);
		else {
			fprint(2, "mk: nothing to mk\n");
			Exit();
		}
	} else {
		if(sflag){
			for(; *argv; argv++)
				if(**argv)
					mk(*argv);
		} else {
			Word *head, *tail, *t;

			/* fake a new rule with all the args as prereqs */
			tail = 0;
			t = 0;
			for(; *argv; argv++)
				if(**argv){
					if(tail == 0)
						tail = t = newword(*argv);
					else {
						t->next = newword(*argv);
						t = t->next;
					}
				}
			if(tail->next == 0)
				mk(tail->s);
			else {
				head = newword("command line arguments");
				addrules(head, tail, strdup(""), VIR, mkinline, 0);
				mk(head->s);
			}
		}
	}
	if(uflag)
		prusage();
	exits(0);
}
예제 #29
0
/*------------------------------------------------------------------------
 *  ipreass  -  reassemble an IP datagram, if necessary
 *	returns packet, if complete; 0 otherwise
 *------------------------------------------------------------------------
 */
struct ep *
ipreass(struct ep *pep)
{
	struct	ep	*pep2;
	struct	ip	*pip;
	int		firstfree;
	int		i;

	pip = (struct ip *)pep->ep_data;

	wait(ipfmutex);

	if ((pip->ip_fragoff & (IP_FRAGOFF|IP_MF)) == 0) {
		signal(ipfmutex);
		return pep;
	}
	IpReasmReqds++;
	firstfree = -1;
	for (i=0; i<IP_FQSIZE; ++i) {
		struct	ipfq	*piq = &ipfqt[i];

		if (piq->ipf_state == IPFF_FREE) {
			if (firstfree == -1)
				firstfree = i;
			continue;
		}
		if (piq->ipf_id != pip->ip_id)
			continue;
		if (piq->ipf_src != pip->ip_src)
			continue;
		/* found a match */
		if (ipfadd(piq, pep) == 0) {
			signal(ipfmutex);
			return 0;
		}
		pep2 = ipfjoin(piq);
		signal(ipfmutex);
		return pep2;
		
	}
	/* no match */

	if (firstfree < 0) {
		/* no room-- drop */
		freebuf(pep);
		signal(ipfmutex);
		return 0;
	}
	ipfqt[firstfree].ipf_q = newq(IP_FQSIZE, QF_WAIT);
	if (ipfqt[firstfree].ipf_q < 0) {
		freebuf(pep);
		signal(ipfmutex);
		return 0;
	}
	ipfqt[firstfree].ipf_src = pip->ip_src;
	ipfqt[firstfree].ipf_id = pip->ip_id;
	ipfqt[firstfree].ipf_ttl = IP_FTTL;
	ipfqt[firstfree].ipf_state = IPFF_VALID;
	ipfadd(&ipfqt[firstfree], pep);
	signal(ipfmutex);
	return 0;
}
예제 #30
0
/*------------------------------------------------------------------------
 * icmp_recv  -  Receive an icmp echo reply packet
 *------------------------------------------------------------------------
 */
int32	icmp_recv (
	 int32	icmpid,			/* ICMP slot identifier		*/
	 char   *buff,			/* Buffer to ICMP data		*/
	 int32	len,			/* Length of buffer		*/
	 uint32	timeout			/* Time to wait in msec		*/
	)
{
	intmask	mask;			/* Saved interrupt mask		*/
	struct	icmpentry *icmptr;	/* Pointer to icmptab entry	*/
	umsg32	msg;			/* Message from recvtime()	*/
	struct	netpacket *pkt;		/* Pointer to packet being read	*/
	int32	datalen;		/* Length of ICMP data area	*/
	char	*icdataptr;		/* Pointer to icmp data		*/
	int32	i;			/* Counter for data copy	*/

	/* Verify that the ID is valid */

	if ( (icmpid < 0) || (icmpid >= ICMP_SLOTS) ) {
		return SYSERR;
	}

	/* Insure only one process touches the table at a time */

	mask = disable();

	/* Verify that the ID has been registered and is idle */

	icmptr = &icmptab[icmpid];
	if (icmptr->icstate != ICMP_USED) {
		restore(mask);
		return SYSERR;
	}

	if (icmptr->iccount == 0) {		/* No packet is waiting */
		icmptr->icstate = ICMP_RECV;
		icmptr->icpid = currpid;
		msg = recvclr();
		msg = recvtime(timeout);	/* Wait for a reply */
		icmptr->icstate = ICMP_USED;
		if (msg == TIMEOUT) {
			restore(mask);
			return TIMEOUT;
		} else if (msg != OK) {
			restore(mask);
			return SYSERR;
		}
	}

	/* Packet has arrived -- dequeue it */

	pkt = icmptr->icqueue[icmptr->ichead++];
	if (icmptr->ichead >= ICMP_SLOTS) {
		icmptr->ichead = 0;
	}
	icmptr->iccount--;

	/* Copy data from ICMP message into caller's buffer */

	datalen = pkt->net_iplen - IP_HDR_LEN - ICMP_HDR_LEN;
	icdataptr = (char *) &pkt->net_icdata;
	for (i=0; i<datalen; i++) {
		if (i >= len) {
			break;
		}
		*buff++ = *icdataptr++;
	}
	freebuf((char *)pkt);
	restore(mask);
	return i;
}