aboutsummaryrefslogtreecommitdiffstats
path: root/tests/osmo-pcap-test/proto.c
blob: 085ca254365ba65dfa6b385ccc95010e708ec1f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * (C) 2012 by Pablo Neira Ayuso <pablo@gnumonks.org>
 * (C) 2012 by On Waves ehf <http://www.on-waves.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later vers
 */

#include <stdlib.h>
#include <netinet/in.h>
#include <linux/if_ether.h>

#include <osmocom/core/linuxlist.h>
#include "proto.h"

static LLIST_HEAD(l2_proto_list);
static LLIST_HEAD(l3_proto_list);
static LLIST_HEAD(l4_proto_list);
#include <stdio.h>

struct osmo_pcap_proto_l2 *osmo_pcap_proto_l2_find(unsigned int pcap_linktype)
{
	struct osmo_pcap_proto_l2 *cur;

	llist_for_each_entry(cur, &l2_proto_list, head) {
		if (cur->l2protonum == pcap_linktype)
			return cur;
	}
	return NULL;
}

void osmo_pcap_proto_l2_register(struct osmo_pcap_proto_l2 *h)
{
	llist_add(&h->head, &l2_proto_list);
}


struct osmo_pcap_proto_l3 *osmo_pcap_proto_l3_find(unsigned int l3protocol)
{
	struct osmo_pcap_proto_l3 *cur;

	llist_for_each_entry(cur, &l3_proto_list, head) {
		if (ntohs(cur->l3protonum) == l3protocol)
			return cur;
	}
	return NULL;
}

void osmo_pcap_proto_l3_register(struct osmo_pcap_proto_l3 *h)
{
	llist_add(&h->head, &l3_proto_list);
}

struct osmo_pcap_proto_l4 *
osmo_pcap_proto_l4_find(unsigned int l4protocol)
{
	struct osmo_pcap_proto_l4 *cur;

	llist_for_each_entry(cur, &l4_proto_list, head) {
		if (cur->l4protonum == l4protocol)
			return cur;
	}
	return NULL;
}

void osmo_pcap_proto_l4_register(struct osmo_pcap_proto_l4 *h)
{
	llist_add(&h->head, &l4_proto_list);
}