Skip to content

Instantly share code, notes, and snippets.

@CN6033
Created November 9, 2014 06:47
Show Gist options
  • Save CN6033/3da25a8f82e1fa8e4695 to your computer and use it in GitHub Desktop.
Save CN6033/3da25a8f82e1fa8e4695 to your computer and use it in GitHub Desktop.
Type-Length-Value
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct TLV {
int type;
int length;
char value[0];
}TLV;
int main() {
int length = 100;
TLV *val = (TLV*) malloc(sizeof(TLV) + length);
val->type = 1;
val->length = length;
strncpy(val->value, "Hello, world!\n", val->length);
printf("%s", val->value);
free(val);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment