forked from unpbook/unpv13e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
name.c
59 lines (52 loc) · 1.13 KB
/
name.c
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
#include "unp.h"
#include <net/pfkeyv2.h>
struct idlist {
int val;
const char *name;
};
static struct idlist satype[] = {
{ SADB_SATYPE_UNSPEC, "unspec" },
{ SADB_SATYPE_AH, "ah" },
{ SADB_SATYPE_ESP, "esp" },
{ SADB_SATYPE_RSVP, "rsvp" },
{ SADB_SATYPE_OSPFV2, "ospfv2" },
{ SADB_SATYPE_RIPV2, "ripv2" },
{ SADB_SATYPE_MIP, "mip" },
{ 0, NULL } };
static struct idlist ahalg[] = {
{ SADB_AALG_NONE, "none" },
{ SADB_AALG_MD5HMAC, "HMAC-MD5-96" },
{ SADB_AALG_SHA1HMAC, "HMAC-SHA-1-96" },
{ 0, NULL } };
static struct idlist espalg[] = {
{ SADB_EALG_NONE, "none" },
{ SADB_EALG_DESCBC, "DES-CBC" },
{ SADB_EALG_3DESCBC, "3DES-CBC" },
{ SADB_EALG_NULL, "NULL" },
{ 0, NULL } };
int
idlistlookup(char *name, struct idlist *il)
{
for (; il->name != NULL; il++) {
if (strcmp(name, il->name) == 0)
return il->val;
}
return -1;
}
int
getsatypebyname(char *name)
{
return idlistlookup(name, satype);
}
int
getsaalgbyname(int type, char *name)
{
switch (type) {
case SADB_SATYPE_AH:
return idlistlookup(name, ahalg);
case SADB_SATYPE_ESP:
return idlistlookup(name, espalg);
default:
return -1;
}
}