@ -27,12 +27,18 @@
# include "suricata-common.h"
# include "suricata-common.h"
# include "util-proto-name.h"
# include "util-proto-name.h"
static int init_once = 0 ;
/**
/**
* \ brief Function to load the protocol names from the specified protocol
* \ brief Function to load the protocol names from the specified protocol
* file .
* file .
*/
*/
void SCProtoNameInit ( )
void SCProtoNameInit ( )
{
{
BUG_ON ( init_once ) ;
init_once + + ;
memset ( known_proto , 0x00 , sizeof ( known_proto ) ) ;
/* Load the known protocols name from the /etc/protocols file */
/* Load the known protocols name from the /etc/protocols file */
FILE * fp = fopen ( PROTO_FILE , " r " ) ;
FILE * fp = fopen ( PROTO_FILE , " r " ) ;
if ( fp ! = NULL ) {
if ( fp ! = NULL ) {
@ -46,17 +52,17 @@ void SCProtoNameInit()
continue ;
continue ;
# if defined(__WIN32) || defined(_WIN32)
# if defined(__WIN32) || defined(_WIN32)
char * name = strtok ( line , " \t " ) ;
char * name = strtok ( line , " \t " ) ;
# else
# else
char * name = strtok_r ( line , " \t " , & ptr ) ;
char * name = strtok_r ( line , " \t " , & ptr ) ;
# endif /* __WIN32 */
# endif /* __WIN32 */
if ( name = = NULL )
if ( name = = NULL )
continue ;
continue ;
# if defined(__WIN32) || defined(_WIN32)
# if defined(__WIN32) || defined(_WIN32)
char * proto_ch = strtok ( NULL , " \t " ) ;
char * proto_ch = strtok ( NULL , " \t " ) ;
# else
# else
char * proto_ch = strtok_r ( NULL , " \t " , & ptr ) ;
char * proto_ch = strtok_r ( NULL , " \t " , & ptr ) ;
# endif /* __WIN32 */
# endif /* __WIN32 */
if ( proto_ch = = NULL )
if ( proto_ch = = NULL )
continue ;
continue ;
@ -66,11 +72,15 @@ void SCProtoNameInit()
continue ;
continue ;
# if defined(__WIN32) || defined(_WIN32)
# if defined(__WIN32) || defined(_WIN32)
char * cname = strtok ( NULL , " \t " ) ;
char * cname = strtok ( NULL , " \t " ) ;
# else
# else
char * cname = strtok_r ( NULL , " \t " , & ptr ) ;
char * cname = strtok_r ( NULL , " \t " , & ptr ) ;
# endif /* __WIN32 */
# endif /* __WIN32 */
if ( known_proto [ proto ] ! = NULL ) {
SCFree ( known_proto [ proto ] ) ;
}
if ( cname ! = NULL ) {
if ( cname ! = NULL ) {
known_proto [ proto ] = SCStrdup ( cname ) ;
known_proto [ proto ] = SCStrdup ( cname ) ;
} else {
} else {
@ -111,9 +121,10 @@ uint8_t SCProtoNameValid(uint16_t proto)
*/
*/
void SCProtoNameDeInit ( )
void SCProtoNameDeInit ( )
{
{
int cnt ;
/* clears the memory of loaded protocol names */
/* clears the memory of loaded protocol names */
for ( uint8_t cnt = 0 ; cnt < 255 ; cnt + + ) {
for ( cnt = 0 ; cnt < 255 ; cnt + + ) {
if ( known_proto [ cnt ] ! = NULL )
if ( known_proto [ cnt ] ! = NULL )
SCFree ( known_proto [ cnt ] ) ;
SCFree ( known_proto [ cnt ] ) ;
}
}
}
}