/* Write a block to a file pointer. Returns 1 for success; 0 for failure. */ int block_write(const struct block *b, FILE *fp) { unsigned char buf[SERIALIZED_BLOCK_LEN]; int n; block_serialize(b, buf); n = fwrite(buf, sizeof(buf), 1, fp); return n >= 0; }
/* Compute the hash value of a block using the current nonce. */ void block_hash(const struct block *b, hash_output h) { unsigned char buf[SERIALIZED_BLOCK_LEN]; SHA256_CTX sha; block_serialize(b, buf); SHA256_Init(&sha); SHA256_Update(&sha, buf, sizeof(buf)); SHA256_Final(h, &sha); }
int packet_serialize(struct packet *p, unsigned char *buf) { if (!p) return 0; int ret = 11; *buf = p->family; *(buf+1) = p->unk1; *(buf+2) = p->dir; *(buf+3) = p->pltype; *(unsigned short *)(buf+4) = htons(p->connid); *(buf+6) = p->subseq; *(buf+7) = p->unk2; *(unsigned short *)(buf+8) = htons(p->sessid); *(buf+10) = p->tail; if (p->data) ret += block_serialize(p->data, buf+11); return ret; }