suricata
app-layer-protos.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2013 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  * \author Anoop Saldanha <anoopsaldanha@gmail.com>
23  */
24 
25 #include "suricata-common.h"
26 #include "app-layer-protos.h"
27 
28 #define CASE_CODE(E) case E: return #E
29 
30 const char *AppProtoToString(AppProto alproto)
31 {
32  const char *proto_name = NULL;
33  enum AppProtoEnum proto = alproto;
34 
35  switch (proto) {
36  case ALPROTO_HTTP:
37  proto_name = "http";
38  break;
39  case ALPROTO_FTP:
40  proto_name = "ftp";
41  break;
42  case ALPROTO_SMTP:
43  proto_name = "smtp";
44  break;
45  case ALPROTO_TLS:
46  proto_name = "tls";
47  break;
48  case ALPROTO_SSH:
49  proto_name = "ssh";
50  break;
51  case ALPROTO_IMAP:
52  proto_name = "imap";
53  break;
54  case ALPROTO_MSN:
55  proto_name = "msn";
56  break;
57  case ALPROTO_JABBER:
58  proto_name = "jabber";
59  break;
60  case ALPROTO_SMB:
61  proto_name = "smb";
62  break;
63  case ALPROTO_SMB2:
64  proto_name = "smb2";
65  break;
66  case ALPROTO_DCERPC:
67  proto_name = "dcerpc";
68  break;
69  case ALPROTO_IRC:
70  proto_name = "irc";
71  break;
72  case ALPROTO_DNS:
73  proto_name = "dns";
74  break;
75  case ALPROTO_MODBUS:
76  proto_name = "modbus";
77  break;
78  case ALPROTO_ENIP:
79  proto_name = "enip";
80  break;
81  case ALPROTO_DNP3:
82  proto_name = "dnp3";
83  break;
84  case ALPROTO_NFS:
85  proto_name = "nfs";
86  break;
87  case ALPROTO_NTP:
88  proto_name = "ntp";
89  break;
90  case ALPROTO_FTPDATA:
91  proto_name = "ftp-data";
92  break;
93  case ALPROTO_TFTP:
94  proto_name = "tftp";
95  break;
96  case ALPROTO_IKEV2:
97  proto_name = "ikev2";
98  break;
99  case ALPROTO_KRB5:
100  proto_name = "krb5";
101  break;
102  case ALPROTO_DHCP:
103  proto_name = "dhcp";
104  break;
105  case ALPROTO_TEMPLATE:
106  proto_name = "template";
107  break;
109  proto_name = "template-rust";
110  break;
111  case ALPROTO_FAILED:
112  proto_name = "failed";
113  break;
114 #ifdef UNITTESTS
115  case ALPROTO_TEST:
116 #endif
117  case ALPROTO_MAX:
118  case ALPROTO_UNKNOWN:
119  break;
120  }
121 
122  return proto_name;
123 }
124 
125 AppProto StringToAppProto(const char *proto_name)
126 {
127  if (proto_name == NULL) return ALPROTO_UNKNOWN;
128 
129  if (strcmp(proto_name,"http")==0) return ALPROTO_HTTP;
130  if (strcmp(proto_name,"ftp")==0) return ALPROTO_FTP;
131  if (strcmp(proto_name,"smtp")==0) return ALPROTO_SMTP;
132  if (strcmp(proto_name,"tls")==0) return ALPROTO_TLS;
133  if (strcmp(proto_name,"ssh")==0) return ALPROTO_SSH;
134  if (strcmp(proto_name,"imap")==0) return ALPROTO_IMAP;
135  if (strcmp(proto_name,"msn")==0) return ALPROTO_MSN;
136  if (strcmp(proto_name,"jabber")==0) return ALPROTO_JABBER;
137  if (strcmp(proto_name,"smb")==0) return ALPROTO_SMB;
138  if (strcmp(proto_name,"smb2")==0) return ALPROTO_SMB2;
139  if (strcmp(proto_name,"dcerpc")==0) return ALPROTO_DCERPC;
140  if (strcmp(proto_name,"irc")==0) return ALPROTO_IRC;
141  if (strcmp(proto_name,"dns")==0) return ALPROTO_DNS;
142  if (strcmp(proto_name,"modbus")==0) return ALPROTO_MODBUS;
143  if (strcmp(proto_name,"enip")==0) return ALPROTO_ENIP;
144  if (strcmp(proto_name,"dnp3")==0) return ALPROTO_DNP3;
145  if (strcmp(proto_name,"nfs")==0) return ALPROTO_NFS;
146  if (strcmp(proto_name,"ntp")==0) return ALPROTO_NTP;
147  if (strcmp(proto_name,"ikev2")==0) return ALPROTO_IKEV2;
148  if (strcmp(proto_name,"krb5")==0) return ALPROTO_KRB5;
149  if (strcmp(proto_name,"dhcp")==0) return ALPROTO_DHCP;
150  if (strcmp(proto_name,"template")==0) return ALPROTO_TEMPLATE;
151  if (strcmp(proto_name,"template-rust")==0) return ALPROTO_TEMPLATE_RUST;
152  if (strcmp(proto_name,"failed")==0) return ALPROTO_FAILED;
153 
154  return ALPROTO_UNKNOWN;
155 }
AppProtoEnum
uint16_t AppProto
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its string equivalent.
AppProto StringToAppProto(const char *proto_name)
Maps a string to its ALPROTO_* equivalent.
uint8_t proto