char *createMsg( char *hdr, TLV tlv) { char *p_msg; // do we need to pad message with zeros ?? uint32_t msg_length; msg_length = strlen(hdr)+tlv.param_length; if( msg_length%4 == 0) { if((p_msg=(char *)malloc(msg_length))==NULL) { printf("Memory allocation has failed"); } memmove(p_msg,hdr,8); msg_length = htonl(msg_length); // 32bit number network byte order needed; memmove(p_msg+4,&msg_length,4); memmove(p_msg+8,&tlv.param_tag,2); memmove(p_msg+10,&tlv.param_length,2); memmove(p_msg+12,tlv.value,tlv.param_length-2); // without param_length field; } else { int padding; padding = msg_length%4; if((p_msg=(char *)malloc(msg_length+padding))==NULL) { printf("Memory allocation has failed"); } memmove(p_msg,hdr,8); msg_length = htonl(msg_length); // 32bit number network byte order needed; memmove(p_msg+4,&msg_length,4); memmove(p_msg+8,&tlv.param_tag,2); memmove(p_msg+10,&tlv.param_length,2); int i; char pad[padding]; for(i =0;i<=padding;i++) { pad[i]='0'; } memmove(p_msg+msg_length+1,&pad,1); } return p_msg; }