c - Serialize directory tree to send over TCP -


i sending dirtree on tcp client application. dir node structure looks this:

struct node {       char *name;       int count_subnodes;       struct node **subnodes;  }; 

to serialize:

void serialize(void *buffer, struct node *n, int *c){     int i;     if(!n)         return;     memcpy(buffer+(*c), n, sizeof(*n));     *c+=sizeof(n);     for(i = 0; < n->count_subnodes; i++){         serialize(buffer, n->subnode[i], c);     } } 

what doing wrong? segfaults when call serialize recursively subnodes. also, need sort of marker delimitation can reconstruct tree on client side?

edit: c keep count of current position in buffer.

edit 2: typo. sizeof(*n) not c. sorry

  1. how know buffer big enough?

  2. sizeof(n) give the size of pointer, not struct; use sizeof(*n)

  3. check n->subnode[i] not null


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -