1 /* Copyright (c) 2006-2009, Stig Venaas, UNINETT AS.
2 * Copyright (c) 2010, UNINETT AS, NORDUnet A/S.
3 * Copyright (c) 2010-2012, NORDUnet A/S. */
4 /* See LICENSE for licensing information. */
7 #include <sys/inttypes.h>
15 #include <arpa/inet.h>
17 struct tlv *maketlv(uint8_t t, uint8_t l, void *v) {
20 tlv = malloc(sizeof(struct tlv));
37 struct tlv *copytlv(struct tlv *in) {
38 return in ? maketlv(in->t, in->l, in->v) : NULL;
41 void freetlv(struct tlv *tlv) {
48 int eqtlv(struct tlv *t1, struct tlv *t2) {
51 if (t1->t != t2->t || t1->l != t2->l)
53 return memcmp(t1->v, t2->v, t1->l) == 0;
56 struct list *copytlvlist(struct list *tlvs) {
58 struct list_node *node;
65 for (node = list_first(tlvs); node; node = list_next(node)) {
66 if (!list_push(out, copytlv((struct tlv *)node->data))) {
74 void freetlvlist(struct list *tlvs) {
76 while ((tlv = (struct tlv *)list_shift(tlvs)))
81 void rmtlv(struct list *tlvs, uint8_t t) {
82 struct list_node *n, *p;
88 tlv = (struct tlv *)n->data;
90 list_removedata(tlvs, tlv);
92 n = p ? list_next(p) : list_first(tlvs);
100 uint8_t *tlv2str(struct tlv *tlv) {
101 uint8_t *s = malloc(tlv->l + 1);
103 memcpy(s, tlv->v, tlv->l);
109 uint8_t *tlv2buf(uint8_t *p, const struct tlv *tlv) {
114 memcpy(p, tlv->v, tlv->l);
116 memset(p, 0, tlv->l);
121 /* Local Variables: */
122 /* c-file-style: "stroustrup" */