File: rtm_map.c

package info (click to toggle)
iproute 980630-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 468 kB
  • ctags: 389
  • sloc: ansic: 8,276; makefile: 104
file content (123 lines) | stat: -rw-r--r-- 2,216 bytes parent folder | download
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * rtm_map.c
 *
 *		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 version.
 *
 * Authors:	Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>

#include "utils.h"

char *rttable_name(int id)
{
	static char buf[64];
	switch (id) {
	case RT_TABLE_UNSPEC:
		return "none";
	case RT_TABLE_MAIN:
		return "main";
	case RT_TABLE_LOCAL:
		return "local";
	case RT_TABLE_DEFAULT:
		return "default";
	default:
		sprintf(buf, "%d", id);
		return buf;
	}
}

char *rtprot_name(int id)
{
	static char buf[64];
	switch (id) {
	case RTPROT_UNSPEC:
		return "none";
	case RTPROT_REDIRECT:
		return "redirect";
	case RTPROT_STATIC:
		return "static";
	case RTPROT_KERNEL:
		return "kernel";
	case RTPROT_BOOT:
		return "remnant";
	case RTPROT_RA:
		return "ra";
	case RTPROT_GATED:
		return "gated";
	case RTPROT_MRT:
		return "mrt";
	case RTPROT_ZEBRA:
		return "zebra";
	default:
		sprintf(buf, "%d", id);
		return buf;
	}
}

char *rtscope_name(int id)
{
	static char buf[64];
	switch (id) {
	case RT_SCOPE_UNIVERSE:
		return "universe";
	case RT_SCOPE_SITE:
		return "site";
	case RT_SCOPE_LINK:
		return "link";
	case RT_SCOPE_HOST:
		return "host";
	case RT_SCOPE_NOWHERE:
		return "nowhere";
	default:
		sprintf(buf, "%d", id);
		return buf;
	}
}

char *rtntype_name(int id)
{
	static char buf[64];
	switch (id) {
	case RTN_UNSPEC:
		return "none";
	case RTN_UNICAST:
		return "unicast";
	case RTN_LOCAL:
		return "local";
	case RTN_BROADCAST:
		return "broadcast";
	case RTN_ANYCAST:
		return "anycast";
	case RTN_MULTICAST:
		return "multicast";
	case RTN_BLACKHOLE:
		return "blackhole";
	case RTN_UNREACHABLE:
		return "unreachable";
	case RTN_PROHIBIT:
		return "prohibit";
	case RTN_THROW:
		return "throw";
	case RTN_NAT:
		return "nat";
	case RTN_XRESOLVE:
		return "xresolve";
	default:
		sprintf(buf, "%d", id);
		return buf;
	}
}