1 /* Copyright (c) 2008-2009, UNINETT AS
2 * Copyright (c) 2010, NORDUnet A/S */
3 /* See LICENSE for licensing information. */
6 #include <sys/inttypes.h>
14 #include <arpa/inet.h>
16 struct tlv *maketlv(uint8_t t, uint8_t l, void *v) {
19 tlv = malloc(sizeof(struct tlv));
36 struct tlv *copytlv(struct tlv *in) {
37 return in ? maketlv(in->t, in->l, in->v) : NULL;
40 void freetlv(struct tlv *tlv) {
47 int eqtlv(struct tlv *t1, struct tlv *t2) {
50 if (t1->t != t2->t || t1->l != t2->l)
52 return memcmp(t1->v, t2->v, t1->l) == 0;
55 struct list *copytlvlist(struct list *tlvs) {
57 struct list_node *node;
64 for (node = list_first(tlvs); node; node = list_next(node)) {
65 if (!list_push(out, copytlv((struct tlv *)node->data))) {
73 void freetlvlist(struct list *tlvs) {
75 while ((tlv = (struct tlv *)list_shift(tlvs)))
80 void rmtlv(struct list *tlvs, uint8_t t) {
81 struct list_node *n, *p;
87 tlv = (struct tlv *)n->data;
89 list_removedata(tlvs, tlv);
91 n = p ? list_next(p) : list_first(tlvs);
99 uint8_t *tlv2str(struct tlv *tlv) {
100 uint8_t *s = malloc(tlv->l + 1);
102 memcpy(s, tlv->v, tlv->l);
108 uint8_t *tlv2buf(uint8_t *p, const struct tlv *tlv) {
113 memcpy(p, tlv->v, tlv->l);
115 memset(p, 0, tlv->l);
120 /* Local Variables: */
121 /* c-file-style: "stroustrup" */