MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / parse_proto

Function parse_proto

socket_info.h:215–309  ·  view source on GitHub ↗

! \brief Sets protocol * \return -1 on error, 0 on success */

Source from the content-addressed store, hash-verified

213 * \return -1 on error, 0 on success
214 */
215inline static int parse_proto(unsigned char* s, long len, int* proto)
216{
217#define PROTO2UINT(a, b, c) (( (((unsigned int)(a))<<16)+ \
218 (((unsigned int)(b))<<8)+ \
219 ((unsigned int)(c)) ) | 0x20202020)
220 unsigned int i;
221 unsigned int j;
222
223 /* must support 2-char arrays for ws
224 * must support 3-char arrays for udp, tcp, tls, wss
225 * must support 4-char arrays for sctp and bond
226 * must support 5-char arrays for ipsec
227 * must support 7-char arrays for hep_tcp and hep_udp */
228 *proto=PROTO_NONE;
229 if ((len < 2 || len > 5) && len != 7) return -1;
230
231 i=PROTO2UINT(s[0], s[1], s[2]);
232 switch(i){
233 case PROTO2UINT('u', 'd', 'p'):
234 if(len==3) { *proto=PROTO_UDP; return 0; }
235 break;
236 case PROTO2UINT('t', 'c', 'p'):
237 if(len==3) { *proto=PROTO_TCP; return 0; }
238 break;
239 case PROTO2UINT('t', 'l', 's'):
240 if(len==3) { *proto=PROTO_TLS; return 0; }
241 break;
242 case PROTO2UINT('s', 'c', 't'):
243 if(len==4 && (s[3]=='p' || s[3]=='P')) {
244 *proto=PROTO_SCTP; return 0;
245 }
246 break;
247 case PROTO2UINT('w', 's', 's'):
248 if(len==3) { *proto=PROTO_WSS; return 0; }
249 break;
250 case PROTO2UINT('b', 'i', 'n'):
251 if(len==3) { *proto=PROTO_BIN; return 0; }
252 else if(len==4 && (s[3]=='s' || s[3]=='S')) {
253 *proto=PROTO_BINS; return 0;
254 }
255 break;
256 case PROTO2UINT('i', 'p', 's'):
257 if(len==5 && (s[3]|0x20)=='e' && (s[4]|0x20)=='c') {
258 *proto=PROTO_IPSEC; return 0;
259 }
260 return -1;
261
262 case PROTO2UINT('h', 'e', 'p'):
263 if (len != 7 || s[3] != '_') return -1;
264
265 j=PROTO2UINT(s[4], s[5], s[6]);
266 switch (j) {
267 case PROTO2UINT('u','d', 'p'):
268 *proto=PROTO_HEP_UDP;
269 return 0;
270 case PROTO2UINT('t','c', 'p'):
271 *proto=PROTO_HEP_TCP;
272 return 0;

Callers 8

parse_phostportFunction · 0.85
mi_bl_get_extraFunction · 0.85
mi_bl_get_ruleFunction · 0.85
fixup_blacklist_protoFunction · 0.85
proto_char2intFunction · 0.85
tcp_store_pathFunction · 0.85
mi_tcp_list_connsFunction · 0.85
trans_loadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected