Esempio n. 1
0
File: tar.c Progetto: aahud/harvey
static Hdr *
readhdr(int ar)
{
	int32_t hdrcksum;
	Hdr *hp;

	hp = getblkrd(ar, Alldata);
	if (hp == nil)
		sysfatal("unexpected EOF instead of archive header in %s",
			arname);
	if (eotar(hp))			/* end-of-archive block? */
		return nil;

	hdrcksum = parsecksum(hp->chksum, name(hp));
	if (hdrcksum == -1 || chksum(hp) != hdrcksum) {
		if (!resync)
			sysfatal("bad archive header checksum in %s: "
				"name %.100s...; expected %#luo got %#luo",
				arname, hp->name, hdrcksum, chksum(hp));
		fprint(2, "%s: skipping past archive header with bad checksum in %s...",
			argv0, arname);
		do {
			hp = getblkrd(ar, Alldata);
			if (hp == nil)
				sysfatal("unexpected EOF looking for archive header in %s",
					arname);
			hdrcksum = parsecksum(hp->chksum, name(hp));
		} while (hdrcksum == -1 || chksum(hp) != hdrcksum);
		fprint(2, "found %s\n", name(hp));
	}
	nexthdr += Tblock*(1 + BYTES2TBLKS(arsize(hp)));
	return hp;
}
Esempio n. 2
0
static void raw_send(const char *str, int payload_len) {
    uint16_t c;
    int len = 8 /* udp header */ + payload_len;

    /* IPv6 header → length */
    uip_buf[19] = len;

    /* UDP header → length */
    uip_buf[59] = len;

    /* initialize UDP checksum to zero */
    uip_buf[60] = 0x00;
    uip_buf[61] = 0x00;

    for (c = 0; c < payload_len; c++)
        uip_buf[62 + c] = str[c];

    /* calculate UDP checksum */
    uint16_t sum = 0;
    sum = len + 17;
    sum = chksum(sum, (uint8_t*)&uip_buf[22], 2 * 16);
    sum = chksum(sum, &uip_buf[54], len);
    sum = (sum == 0 ? 0xffff : ~sum);
    if (sum == 0)
        sum = 0xffff;

    uip_buf[60] = (sum & 0xFF00) >> 8;
    uip_buf[61] = (sum & 0x00FF);

    uip_len = 62 + payload_len;
    transmit_packet();
}
Esempio n. 3
0
static u16_t
upper_layer_chksum(u8_t proto)
{
  /* Added volatile keyword here because AVR targets seem to
   * have problems with this function otherwise. The origin of
   * these problems should be investigated. See:
   * <http://sourceforge.net/apps/mantisbt/contiki/view.php?id=3>
   */
  volatile static u16_t upper_layer_len;
  volatile static u16_t sum;
  
  upper_layer_len = (((u16_t)(UIP_IP_BUF->len[0]) << 8) + UIP_IP_BUF->len[1]) ;
  
  /* First sum pseudoheader. */
  /* IP protocol and length fields. This addition cannot carry. */
  sum = upper_layer_len + proto;
  /* Sum IP source and destination addresses. */
  sum = chksum(sum, (u8_t *)&UIP_IP_BUF->srcipaddr, 2 * sizeof(uip_ipaddr_t));

  /* Sum TCP header and data. */
  sum = chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN],
               upper_layer_len);
    
  return (sum == 0) ? 0xffff : uip_htons(sum);
}
/*---------------------------------------------------------------------------*/
static uint16_t
ipv4_transport_checksum(uint8_t *packet, uint16_t len, uint8_t proto)
{
  uint16_t transport_layer_len;
  uint16_t sum;
  struct ipv4_hdr *v4hdr = (struct ipv4_hdr *)packet;

  transport_layer_len = len - IPV4_HDRLEN;

  /* First sum pseudoheader. */

  if(proto != IP_PROTO_ICMPV4) {
    /* IP protocol and length fields. This addition cannot carry. */
    sum = transport_layer_len + proto;
    /* Sum IP source and destination addresses. */
    sum = chksum(sum, (uint8_t *)&v4hdr->srcipaddr, 2 * sizeof(uip_ip4addr_t));
  } else {
    /* ping replies' checksums are calculated over the icmp-part only */
    sum = 0;
  }

  /* Sum transport layer header and data. */
  sum = chksum(sum, &packet[IPV4_HDRLEN], transport_layer_len);

  return (sum == 0) ? 0xffff : uip_htons(sum);
}
Esempio n. 5
0
File: dhcp.c Progetto: DRTEK/relayd
bool relayd_handle_dhcp_packet(struct relayd_interface *rif, void *data, int len, bool forward, bool parse)
{
	struct ip_packet *pkt = data;
	struct udphdr *udp;
	struct dhcp_header *dhcp;
	struct relayd_host *host;
	int udplen;
	uint16_t sum;

	if (pkt->eth.ether_type != htons(ETH_P_IP))
		return false;

	if (pkt->iph.version != 4)
		return false;

	if (pkt->iph.protocol != IPPROTO_UDP)
		return false;

	udp = (void *) ((char *) &pkt->iph + (pkt->iph.ihl << 2));
	dhcp = (void *) (udp + 1);

	udplen = ntohs(udp->len);
	if (udplen > len - ((char *) udp - (char *) data))
		return false;

	if (udp->dest != htons(67) && udp->source != htons(67))
		return false;

	if (dhcp->op != 1 && dhcp->op != 2)
		return false;

	if (!forward)
		return true;

	if (dhcp->op == 2) {
		host = relayd_refresh_host(rif, pkt->eth.ether_shost, (void *) &pkt->iph.saddr);
		if (host && parse)
			parse_dhcp_options(host, dhcp, udplen - sizeof(struct udphdr));
	}

	DPRINTF(2, "%s: handling DHCP %s\n", rif->ifname, (dhcp->op == 1 ? "request" : "response"));

	dhcp->flags |= htons(DHCP_FLAG_BROADCAST);

	udp->check = 0;
	sum = udplen + IPPROTO_UDP;
	sum = chksum(sum, (void *) &pkt->iph.saddr, 8);
	sum = chksum(sum, (void *) udp, udplen);
	if (sum == 0)
		sum = 0xffff;

	udp->check = htons(~sum);

	relayd_forward_bcast_packet(rif, data, len);

	return true;
}
Esempio n. 6
0
void check_crypto_v2(const struct check_opt *opt)
{
	if (opt->dochecksum)
		chksum();
	if (opt->doversion || opt->dohardwareversion || opt->doremoveversion)
		check_version_info(0, opt->doversion, opt->dohardwareversion,
				opt->doremoveversion, 1);
	/*
	 * Modern signed image support is backward compatible, so we don't
	 * do the crypto check until this point. (That is we have stripped
	 * of old style 16bit checksum and the product/version information).
	 * We also leave the sign structures on the image data, so they get
	 * written to flash as well. However, if it is a gzipped image, we
	 * will need to trim off the signature before we decompress.
	 */
	if (opt->dochecksum) {
		int cryptorc = check_crypto_signature();
		/*
		 * If there is SHA256 or crypto info, there should also be an extra
		 * copy of the version info just before it. (ie. a signed/checksummed
		 * copy.) If we care about version info (and there's a crypto header
		 * present), check this stuff too.
		 */
		if ((opt->doversion || opt->dohardwareversion) && cryptorc == CRYPTO_CHECK_OK) {
			int rc = check_version_info(fb_meta_len(), opt->doversion, opt->dohardwareversion, 0, 0);
			if (rc == 5)
				notice("Warning: no signed version information present in image.");
		}
	}
}
Esempio n. 7
0
/* vbios should at least be NV_PROM_SIZE bytes long */
int vbios_upload_pramin(int cnum, uint8_t *vbios, int length)
{
	uint64_t old_bar0_pramin = 0;
	uint32_t ret = EUNK;
	int i = 0;

	if (nva_cards[cnum]->chipset.chipset < 0x04) {
		return ECARD;
	}

	/* Update the checksum */
	chksum(vbios, length);

	fprintf(stderr, "Attempt to upload the vbios to card %i (nv%02x) using PRAMIN\n",
			cnum, nva_cards[cnum]->chipset.chipset);

	if (nva_cards[cnum]->chipset.card_type >= 0x50) {
		uint64_t vbios_vram = (uint64_t)(nva_rd32(cnum, 0x619f04) & ~0xff) << 8;

		if (!vbios_vram)
			vbios_vram =((uint64_t)nva_rd32(cnum, 0x1700) << 16) + 0xf0000;

		old_bar0_pramin = nva_rd32(cnum, 0x1700);
		nva_wr32(cnum, 0x1700, vbios_vram >> 16);
	}
Esempio n. 8
0
File: ip.c Progetto: tongban/eos
/* ----------------------------------------------------------------------
 *                             ip_output()
 * 功能:由IP模块发送一个数据包
 * 参数: 
 * 返回值:无
 * 说明:无
 * --------------------------------------------------------------------- */
void ip_output( pbuf_t * pbuf, ip_addr_t dest, uint16 len, uint8 pro, uint8 ttl )
{
    uint8   i;
    ip_hdr_t * hdr;
    
    if( pbuf == ( pbuf_t * )0 )
        return;

    /* 填充头部 */
    pbuf->app_data -= sizeof( ip_hdr_t );
    hdr = (ip_hdr_t *)( pbuf->app_data );
    hdr->hlen = sizeof( ip_hdr_t ) / 4;
    hdr->version = IPV4;
    hdr->tos = 0;
    hdr->to_len = htons( len + sizeof( ip_hdr_t ) );
    hdr->id = htons( seq++ );        
    hdr->flag = 0;                          
    hdr->offset = 0;
    hdr->ttl = ttl;
    hdr->protocol = pro;
    hdr->chksum = 0;
    hdr->src_ip = htonl( local_ip );
    hdr->dest_ip = htonl( dest );
    hdr->chksum = chksum( (uint16 *)hdr, sizeof( ip_hdr_t ) );

    /* 直接由网络接口发出或发至网关 */
    if( (dest & net_mask) == (local_ip & net_mask) ) 
        arp_output( pbuf, dest );
    else
        arp_output( pbuf, gate_way );
}
Esempio n. 9
0
/*-----------------------------------------------------------------------------------*/
uint16_t
uip_ipchksum(void)
{  
  chksum_ptr = (uint16_t)uip_buf + UIP_LLH_LEN;
  chksum_len = UIP_IPH_LEN;  
  return chksum();
}
Esempio n. 10
0
/*-----------------------------------------------------------------------------------*/
u16_t
uip_ipchksum(void)
{  
  chksum_ptr = (u16_t)uip_buf + UIP_LLH_LEN;
  chksum_len = 20;  
  return chksum();
}
Esempio n. 11
0
/* input gw10 raw message ------------------------------------------------------
* input next gw10 raw message from stream
* args   : raw_t *raw   IO     receiver raw data control struct
*          unsigned char data I stream data (1 byte)
* return : status (-1: error message, 0: no message, 1: input observation data,
*                  2: input ephemeris, 3: input sbas message,
*                  9: input ion/utc parameter)
*
* notes  : to specify input options, set raw->opt to the following option
*          strings separated by spaces.
*
*          -EPHALL    : input all ephemerides
*
*-----------------------------------------------------------------------------*/
extern int input_gw10(raw_t *raw, unsigned char data)
{
    int stat;
    trace(5,"input_gw10: data=%02x\n",data);
    
    raw->buff[raw->nbyte++]=data;
    
    /* synchronize frame */
    if (raw->buff[0]!=GW10SYNC) {
        raw->nbyte=0;
        return 0;
    }
    if (raw->nbyte>=2&&!(raw->len=msglen(raw->buff[1]))) {
        raw->nbyte=0;
        return 0;
    }
    if (raw->nbyte<2||raw->nbyte<raw->len) return 0;
    
    if (!chksum(raw->buff,raw->len)) {
        tracet(2,"gw10 message checksum error msg=%d\n",raw->buff[1]);
        raw->buff[0]=0;
        raw->nbyte=0;
        return -1;
    }
    /* decode gw10 raw message */
    stat=decode_gw10(raw);
    
    raw->buff[0]=0;
    raw->nbyte=0;
    
    return stat;
}
Esempio n. 12
0
/*-----------------------------------------------------------------------------------*/
uint16_t
uip_chksum(uint16_t *buf, uint16_t len)
{
  /*  unsigned long sum;

  sum = 0;

  chksum_ptr = (uint16_t)buf;
  while(len >= 256) {  
    chksum_len = 256;
    sum += chksum();
    len -= 256;
    chksum_ptr += 256;
  }

  if(len < 256) {
    chksum_len = len;
    sum += chksum();
  }

  while((sum >> 16) != 0) {
    sum = (sum >> 16) + (sum & 0xffff);
  }

  return sum;*/

  chksum_len = len;
  chksum_ptr = (uint16_t)buf;
  return chksum();
}
/*---------------------------------------------------------------------------*/
static uint16_t
ipv4_checksum(struct ipv4_hdr *hdr)
{
  uint16_t sum;

  sum = chksum(0, (uint8_t *)hdr, IPV4_HDRLEN);
  return (sum == 0) ? 0xffff : uip_htons(sum);
}
Esempio n. 14
0
static inline void
insert_hash(struct tfilter *filter, uint64_t sec, char *buf)
{
	struct dhash *hash;

	hash = filter->dhash + sec;
	hash->hash = chksum(buf);
	gettimeofday(&hash->time, NULL);
}
Esempio n. 15
0
void check_crypto_v1(const struct check_opt *opt)
{
	check_crypto_signature();
	if (opt->dochecksum)
		chksum();
	if (opt->doversion || opt->dohardwareversion || opt->doremoveversion)
		check_version_info(0, opt->doversion, opt->dohardwareversion,
				opt->doremoveversion, 1);
}
Esempio n. 16
0
/*---------------------------------------------------------------------------*/
u16_t
uip_ipchksum(void)
{
  u16_t sum;

  sum = chksum(0, &uip_buf[UIP_LLH_LEN], UIP_IPH_LEN);
  PRINTF("uip_ipchksum: sum 0x%04x\n", sum);
  return (sum == 0) ? 0xffff : uip_htons(sum);
}
Esempio n. 17
0
static inline void
check_hash(struct tfilter *filter, uint64_t sec, char *buf, char *type)
{
	uint64_t sum;
	struct dhash *hash;

	hash = filter->dhash + sec;
	if (!hash->time.tv_sec)
		return;

	sum = chksum(buf);
	if (hash->hash != chksum(buf)) {
		struct timeval now;
		gettimeofday(&now, NULL);
		DBG("%s: hash table: 0x%020" PRIx64 " at %012lu.%06lu, "
		    "from disk: 0x%020" PRIx64 " at %012lu.%06lu\n",
		    type, hash->hash, hash->time.tv_sec,
		    hash->time.tv_usec, sum, now.tv_sec, now.tv_usec);
	}
}
Esempio n. 18
0
static uint16_t
upper_layer_chksum(uint8_t proto)
{
  uint16_t upper_layer_len;
  uint16_t sum;
  
  upper_layer_len = (((uint16_t)(UIP_IP_BUF->len[0]) << 8) + UIP_IP_BUF->len[1]) ;
  
  /* First sum pseudoheader. */
  /* IP protocol and length fields. This addition cannot carry. */
  sum = upper_layer_len + proto;
  /* Sum IP source and destination addresses. */
  sum = chksum(sum, (uint8_t *)&UIP_IP_BUF->srcipaddr, 2 * sizeof(uip_ipaddr_t));

  /* Sum TCP header and data. */
  sum = chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN],
               upper_layer_len);
    
  return (sum == 0) ? 0xffff : uip_htons(sum);
}
Esempio n. 19
0
int verify_chksum(char* in) {
	char chk[5];
	ptrdiff_t count = (in[1]-'0')*100 +  (in[2]-'0')*10 + (in[3]-'0');
	sprintf(chk, "%04x", chksum(in+1, in+count-5));
	debug("Extracted count: %ti, chksum: %s", count, chk);
	if (strncasecmp(chk,in+count-5, 4) != 0) { // NOTE: strncasecmp is POSIX
		fprintf(stderr, "ERROR in transmission, checksum fail.\n");
		return -1;
	}
	debug("Checksum matched.");
	return count;
}
/*---------------------------------------------------------------------------*/
static uint16_t
ipv6_transport_checksum(uint8_t *packet, uint16_t len, uint8_t proto)
{
  uint16_t transport_layer_len;
  uint16_t sum;
  struct ipv6_hdr *v6hdr = (struct ipv6_hdr *)packet;

  transport_layer_len = len - IPV6_HDRLEN;

  /* First sum pseudoheader. */

  /* IP protocol and length fields. This addition cannot carry. */
  sum = transport_layer_len + proto;
  /* Sum IP source and destination addresses. */
  sum = chksum(sum, (uint8_t *)&v6hdr->srcipaddr, sizeof(uip_ip6addr_t));
  sum = chksum(sum, (uint8_t *)&v6hdr->destipaddr, sizeof(uip_ip6addr_t));

  /* Sum transport layer header and data. */
  sum = chksum(sum, &packet[IPV6_HDRLEN], transport_layer_len);

  return (sum == 0) ? 0xffff : uip_htons(sum);
}
Esempio n. 21
0
/**
* Builds and returns the next packet, or NULL
* if no more data is available.
*/
void *get_next_packet(int sequence, int *len) {
    //store sent packets in buffer
    if (wind_cache[sequence % WIND_SIZE])
    {
        void* cached_pkt = wind_cache[sequence % WIND_SIZE];
        int cached_header_seq = read_hseq(cached_pkt);
        if (cached_header_seq == sequence ) { 
            //packets are only sent from the buffer if packet loss or a timeout occured
            debug_time = SEND_TIMEOUT; 
            mylog( "[From Cache] %i\n", cached_header_seq);
            *len = sizeof(header) + read_hlength(cached_pkt);
            return cached_pkt;
        }
    }
    //increase timeout
    debug_time += SHORT_TIMEOUT; 
    char *data = malloc(DATA_SIZE);
    int data_length = get_next_data(data, DATA_SIZE);
    if (data_length == 0) {
        free(data);
        return NULL;
    }
    
    //create header for packet
    header *myheader = make_header(sequence, data_length, 0, 0);
    
    //create the packet
    void *pkt = malloc(sizeof(header) + data_length + sizeof(checksum_t));
    memcpy(pkt, myheader, sizeof(header));
    memcpy(((char *) pkt) + sizeof(header), data, data_length);
    
    //calculate the checksum for the packet and attach
    checksum_t chksm = chksum(data, data_length); 
    memcpy(((char *) pkt) + sizeof(header) + data_length, &chksm, sizeof(checksum_t)); 
    free(data);
    free(myheader);
    
    //len = packet size in bytes
    *len = sizeof(header) + data_length + sizeof(checksum_t);
    mylog("Checksum %d\n", get_chksum(pkt, data_length + sizeof(header)));
    
    
    if (wind_cache[sequence % WIND_SIZE])
    {
        free(wind_cache[sequence % WIND_SIZE]);
    }
    wind_cache[sequence % WIND_SIZE] = (void*)malloc(sizeof(header) + data_length + sizeof(checksum_t));
    memcpy(wind_cache[sequence % WIND_SIZE], pkt, sizeof(header) + data_length + sizeof(checksum_t));

    return pkt;
}
Esempio n. 22
0
int c_file(const char* path, const struct stat* st, int type, struct FTW *ftw) {
	int l;
	char b[END];
	FILE *f = NULL;
	struct passwd *pw = getpwuid(st->st_uid);
	struct group *gr = getgrgid(st->st_gid);

	memset(b, 0, END);
	memset(b+SIZE, '0', 12);
	strcpy(b+MAGIC, "ustar");
	strcpy(b+VERS, "00");
	snprintf(b+NAME, 100, "%s", path);
	snprintf(b+MODE, 8, "%.7o", (unsigned)st->st_mode&0777);
	snprintf(b+UID,  8, "%.7o", (unsigned)st->st_uid);
	snprintf(b+GID,  8, "%.7o", (unsigned)st->st_gid);
	snprintf(b+MTIME,12, "%.11o", (unsigned)st->st_mtime);
	snprintf(b+UNAME, 32, "%s", pw->pw_name);
	snprintf(b+GNAME, 32, "%s", gr->gr_name);	
	mode_t mode = st->st_mode;
	if(S_ISREG(mode)) {
		b[TYPE] = REG;
		snprintf(b+SIZE, 12, "%.11o", (unsigned)st->st_size);
		f = fopen(path, "r");
	} else if(S_ISDIR(mode)) {
		b[TYPE] = DIRECTORY;
	} else if(S_ISLNK(mode)) {
		b[TYPE] = SYMLINK;
		readlink(path, b+LINK, 99);
	} else if(S_ISCHR(mode)) {
		b[TYPE] = CHARDEV;
		snprintf(b+MAJ,  8, "%.7o", (unsigned)major(st->st_dev));
		snprintf(b+MIN,  8, "%.7o", (unsigned)minor(st->st_dev));
	} else if(S_ISBLK(mode)) {
		b[TYPE] = BLOCKDEV;
		snprintf(b+MAJ,  8, "%.7o", (unsigned)major(st->st_dev));
		snprintf(b+MIN,  8, "%.7o", (unsigned)minor(st->st_dev));
	} else if(S_ISFIFO(mode)) {
		b[TYPE] = FIFO;
	}
	chksum(b, b+CHK);
	fwrite(b, END, 1, stdout);
	if(!f)
		return 0;
	while((l = fread(b, 1, END, f)) > 0) {
		if(l<END)
			memset(b+l, 0, END-l);
		fwrite(b, END, 1, stdout);
	}
	fclose(f);
	return 0;	
}
Esempio n. 23
0
int flat1_checkfs(void)
{
	struct flathdr1 hdr;
	unsigned int len, size, sum;
	unsigned char buf[BUF_SIZE];
	unsigned int n = 0;

	if (flat_seek(0L, SEEK_SET) != 0L)
		return ERROR_CODE();

	/* Check that header is a valid version 1/2 header */
	if (flat_read(&hdr, sizeof(hdr)) != sizeof(hdr))
		return ERROR_CODE();

	if ((hdr.magic != FLATFS_MAGIC) && (hdr.magic != FLATFS_MAGIC_V2))
		return ERROR_CODE();

	len = flat_dev_length();

	/* XXX - mn
	 * We calculate the checksum wrongly here.
	 *
	 * The trick to the bug is that size != position in file,  since the
	 * first time through we read size==sizeof(hdr),  but increment size by
	 * sizeof(buf).
	 *
	 * Because sizeof(hdr) == 8 and sizeof(buf) == 1024,  we end up not
	 * including the last 1008 bytes, since we start reading 1024 bytes
	 * chunks from position 16.
	 */
	for (sum = 0, size = sizeof(hdr); (size < len); size += sizeof(buf)) {
		n = (size > sizeof(buf)) ? sizeof(buf) :  size;
		if (flat_read(&buf[0], n) != n)
			return ERROR_CODE();
		sum += chksum(&buf[0], n);
	}

#ifdef DEBUG
	syslog(LOG_DEBUG, "flat_checkfs() calculated checksum over %d "
		"bytes = %u", len, sum);
#endif

	if (sum != hdr.chksum) {
		syslog(LOG_ERR, "bad header checksum");
		return ERROR_CODE();
	}

	return 0;
}
Esempio n. 24
0
int pkt_shape_tcpwin(struct pkt_iphdr_t *iph, uint16_t win) {
  if (iph->protocol == PKT_IP_PROTO_TCP) {
    struct pkt_tcphdr_t *tcph =
      (struct pkt_tcphdr_t *)(((uint8_t *)iph) + PKT_IP_HLEN);
    /*log_dbg("TCP Window %d", ntohs(tcph->win));*/
    if (ntohs(tcph->win) > win) {
#if(_debug_ > 1)
      syslog(LOG_DEBUG, "Rewriting TCP Window %d", win);
#endif
      tcph->win = htons(win);
      chksum(iph);
    }
  }
  return 0;
}
Esempio n. 25
0
File: sltar.c Progetto: Gottox/sltar
int x(char *fname, int l, char b[END]){
	static char lname[101] = {0}, chk[8] = {0};
	int r = 0;
	FILE *f = NULL;

	memcpy(lname, b+LINK, 100);
	unlink(fname);
	switch(b[TYPE]) {
	case REG:
		r = !(f = fopen(fname, "w")) ||
			chmod(fname,strtoul(b + MODE, 0, 8));
		break;
	case HARDLINK:
		r = link(lname,fname);
		break;
	case SYMLINK:
		r = symlink(lname,fname);
		break;
	case DIRECTORY:
		r = mkdir(fname,(mode_t) strtoull(b + MODE,0,8));
		break;
	case CHARDEV:
	case BLOCKDEV:
		r = mknod(fname, (b[TYPE] == CHARDEV ?
				S_IFCHR : S_IFBLK) | strtoul(b + MODE,0,8),
					makedev(strtoul(b + MAJ,0,8),
						strtoul(b + MIN,0,8)));
		break;
	case FIFO:
		r = mknod(fname, S_IFIFO | strtoul(b + MODE, 0, 8), 0);
		break;
	default:
		fprintf(stderr,"%s: unsupported filetype %c\n", fname, b[TYPE]);
	}
	if(r || (getuid() == 0 && chown(fname, strtoul(b + UID, 0, 8),
					strtoul(b + GID, 0, 8))))
		perror(fname);
	chksum(b, chk);
	if(strncmp(b+CHK, chk, 8))
		fprintf(stderr, "%s: chksum failed\n", fname);

	for(; l > 0; l -= END){
		fread(b, END, 1, stdin);
		if(f) fwrite(b, MIN(l, 512), 1, f);
	}
	if(f) fclose(f);
	return 0;
}
Esempio n. 26
0
/**
 *  generate product number from RIP key
 *
 *  product[]  : buffer for 12 byte string
 *  rip_key[]  : 256-bit key from flash memory
 *
 */
void ripkey2product(char product[], uint8_t rip_key[]) {
    uint8_t dgst[20];
    SHA_CTX ctx;
    int i, j;
    
    product[PRODUCT_NBR_LEN] = 0;

    SHA1_Init(&ctx);
    SHA1_Update(&ctx, rip_key, RIP_KEY_LEN);
    SHA1_Update(&ctx, "WLAN", 4);
    SHA1_Final(dgst, &ctx);

    for (i = 0, j = 0; i < PRODUCT_NBR_LEN / 2; i++) {
        product[j++] = BIN2HEX((dgst[i] >> 4));
        product[j++] = BIN2HEX((dgst[i] & 0xF));
    }
    product[11] = BIN2HEX(chksum(product));
}
Esempio n. 27
0
/*---------------------------------------------------------------------------*/
static void
slip_input_callback(void)
{
  unsigned char i;
  unsigned short chek_summ,chek_summ_recv;
  if (strncmp(uip_buf, "AdressTarget", 12) == 0){
    chek_summ =chksum(chek_summ,(uint8_t*)uip_buf,16);
    chek_summ_recv = uip_buf[16];
    chek_summ_recv |= ((uint16_t)uip_buf[17])<<8;
    if (chek_summ_recv==chek_summ){
      //set new IPv6 addres
      uip_ipaddr_t ipaddr;
      uip_lladdr_t lladdr;
      lladdr.addr[0] = 0x00;
  		lladdr.addr[1] = 0x12;
  		lladdr.addr[2] = 0x4b;
  		lladdr.addr[3] = 0x00;
      lladdr.addr[4] = uip_buf[12];
      lladdr.addr[5] = uip_buf[13];
      lladdr.addr[6] = uip_buf[14];
      lladdr.addr[7] = uip_buf[15];
      for (i=0;i<4;i++){
        if (uip_buf[12+i]!= uip_ds6_if.addr_list[0].ipaddr.u8[12+i])
          break;
      }
      if (i<4){
        uip_ds6_addr_rm(&uip_ds6_if.addr_list[0]);
        uip_ip6addr(&ipaddr, 0x2001, 0x0db8, 0, 0x0212, 0, 0, 0, 0);
        uip_ds6_set_addr_iid(&ipaddr, &lladdr);
        uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
        uip_buf[12] = uip_ds6_if.addr_list[0].ipaddr.u8[12];
        uip_buf[13] = uip_ds6_if.addr_list[0].ipaddr.u8[13];
        uip_buf[14] = uip_ds6_if.addr_list[0].ipaddr.u8[14];
        uip_buf[15] = uip_ds6_if.addr_list[0].ipaddr.u8[15];
        slip_write(uip_buf, 16);
        print_local_addresses();
      }
    }
  }
 // PRINTF("SIN: %u\n", uip_len);

}
Esempio n. 28
0
/*---------------------------------------------------------------------------*/
static void
slip_input_callback(void)
{
  unsigned char i;
  unsigned short chek_summ,chek_summ_recv;
  static uip_ipaddr_t prefix;
  chek_summ =0;
 // PRINTF("SIN: %u\n", uip_len);
  if(uip_buf[0] == '!') {
    PRINTF("Got configuration message of type %c\n", uip_buf[1]);
    uip_clear_buf();
    if(uip_buf[1] == 'P') {
      chek_summ =chksum(chek_summ,(uint8_t*)uip_buf,10);
      chek_summ_recv = uip_buf[10];
      chek_summ_recv |= ((uint16_t)uip_buf[11])<<8;
      if (chek_summ_recv==chek_summ){
        /* Here we set a prefix !!! */
        memset(&prefix, 0, 16);
        memcpy(&prefix, &uip_buf[2], 8);
        PRINTF("Setting prefix ");
        PRINT6ADDR(&prefix);
        PRINTF("\n");
        set_prefix_64(&prefix);
      }
    }
  } else if (uip_buf[0] == '?') {
    PRINTF("Got request message of type %c\n", uip_buf[1]);
    if(uip_buf[1] == 'M') {
      char* hexchar = "0123456789abcdef";
      int j;
      /* this is just a test so far... just to see if it works */
      uip_buf[0] = '!';
      for(j = 0; j < 8; j++) {
        uip_buf[2 + j * 2] = hexchar[uip_lladdr.addr[j] >> 4];
        uip_buf[3 + j * 2] = hexchar[uip_lladdr.addr[j] & 15];
      }
      uip_len = 18;
      slip_send();
    }
Esempio n. 29
0
/* decode superstar 2 raw message --------------------------------------------*/
static int decode_ss2(raw_t *raw)
{
    unsigned char *p=raw->buff;
    int type=U1(p+1);
    
    trace(3,"decode_ss2: type=%2d\n",type);
    
    if (!chksum(raw->buff,raw->len)) {
        trace(2,"ss2 message checksum error: type=%d len=%d\n",type,raw->len);
        return -1;
    }
    sprintf(raw->msgtype,"SS2: type=%2d len=%3d",type,raw->len);
    
    switch (type) {
        case ID_SS2LLH : return decode_ss2llh (raw);
        case ID_SS2ECEF: return decode_ss2ecef(raw);
        case ID_SS2RAW : return decode_ss2meas(raw);
        case ID_SS2EPH : return decode_ss2eph (raw);
        case ID_SS2SBAS: return decode_ss2sbas(raw);
    }
    return 0;
}
Esempio n. 30
0
File: sender.c Progetto: popacai/SWP
void handle_incoming_acks(Sender * sender,
                          LLnode ** outgoing_frames_head_ptr)
{
    //TODO: Suggested steps for handling incoming ACKs
    //    1) Dequeue the ACK from the sender->input_framelist_head
    //    2) Convert the char * buffer to a Frame data type
    //    3) Check whether the frame is corrupted
    //    4) Check whether the frame is for this sender
    //    5) Do sliding window protocol for sender/receiver pair   
    int incoming_msgs_length = ll_get_length(sender->input_framelist_head);
    while (incoming_msgs_length > 0)
    {
        LLnode * ll_inmsg_node = ll_pop_node(&sender->input_framelist_head);
        incoming_msgs_length = ll_get_length(sender->input_framelist_head);
        char * raw_char_buf = (char *) ll_inmsg_node->value;
        Frame * inframe = convert_char_to_frame(raw_char_buf);
	short checksum;

	checksum = chksum((unsigned short*) raw_char_buf, 
			    MAX_FRAME_SIZE / 2);
	if (checksum)
	{
	    fprintf(stderr, "send checksum error\n");
	    continue;
	}
        free(raw_char_buf);

	if (sender->send_id == inframe->dst)
	{
	    if (inframe->flag == ACK)
	    {
		recv_ack(sender, inframe);
	    }
	}

	free(inframe);
    }
}