75
75
# define TCP (0x7463700000000000llu)
76
76
# define UDP (0x7564700000000000llu)
77
77
#else
78
- #error
79
78
# error "byte order unknown"
80
79
#endif
81
80
82
81
static really_inline int32_t scan_protocol (
83
- const char * name , size_t length )
82
+ const char * name , size_t length , uint8_t * protocol )
84
83
{
85
84
static const int8_t zero_masks [48 ] = {
86
85
-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
@@ -101,22 +100,11 @@ static really_inline int32_t scan_protocol(
101
100
key &= mask ;
102
101
103
102
if (key == TCP )
104
- return 6 ;
105
- if (key == UDP )
106
- return 17 ;
107
-
108
- if (length > 3 ) // protocol numbers must be between 0 and 255
109
- return -1 ;
110
-
111
- uint8_t digit ;
112
- int32_t number = 0 ;
113
- size_t index = 0 ;
114
- while ((digit = (uint8_t )name [index ++ ] - '0' ) <= 9 )
115
- number = number * 10 + digit ;
116
-
117
- if (index != length || number > 255 )
118
- return -1 ;
119
- return number ;
103
+ return (void )(* protocol = 6 ), 1 ;
104
+ else if (key == UDP )
105
+ return (void )(* protocol = 17 ), 1 ;
106
+ else
107
+ return scan_int8 (name , length , protocol );
120
108
}
121
109
122
110
typedef struct service service_t ;
@@ -131,7 +119,6 @@ struct service {
131
119
#define UNKNOWN_SERVICE () { { "", 0 }, 0 }
132
120
#define SERVICE (name , port ) { { name, sizeof(name) - 1 }, port }
133
121
134
- // FIXME: state we're not interested in reverse lookup for wks!
135
122
static const service_t services [64 ] = {
136
123
UNKNOWN_SERVICE (),
137
124
SERVICE ("snmptrap" , 162 ),
0 commit comments