Created
November 9, 2014 06:47
-
-
Save CN6033/3da25a8f82e1fa8e4695 to your computer and use it in GitHub Desktop.
Type-Length-Value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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