Local raw receive loop */
| 4938 | |
| 4939 | /* Local raw receive loop */ |
| 4940 | int raw_capture_rcv_loop(int rsock, int port1, int port2, int ipip) { |
| 4941 | |
| 4942 | |
| 4943 | static char buf [BUF_SIZE+1]; |
| 4944 | union sockaddr_union from; |
| 4945 | union sockaddr_union to; |
| 4946 | int len; |
| 4947 | struct ip *iph; |
| 4948 | struct udphdr *udph; |
| 4949 | char* udph_start; |
| 4950 | unsigned short udp_len; |
| 4951 | int offset = 0; |
| 4952 | char* end; |
| 4953 | unsigned short dst_port; |
| 4954 | unsigned short src_port; |
| 4955 | struct ip_addr dst_ip, src_ip; |
| 4956 | struct ipc_msg_pack *ipc_pack; |
| 4957 | |
| 4958 | |
| 4959 | for(;;) { |
| 4960 | |
| 4961 | len = recvfrom(rsock, buf, BUF_SIZE, 0, 0, 0); |
| 4962 | |
| 4963 | if (len<0){ |
| 4964 | if (len==-1){ |
| 4965 | LM_ERR("recvfrom: %s [%d]\n", |
| 4966 | strerror(errno), errno); |
| 4967 | if ((errno==EINTR)||(errno==EWOULDBLOCK)) |
| 4968 | continue; |
| 4969 | else goto error; |
| 4970 | }else{ |
| 4971 | LM_DBG("recvfrom error: %d\n", len); |
| 4972 | continue; |
| 4973 | } |
| 4974 | } |
| 4975 | |
| 4976 | end=buf+len; |
| 4977 | |
| 4978 | offset = ipip ? sizeof(struct ip) : ETHHDR; |
| 4979 | |
| 4980 | if (len < (sizeof(struct ip)+sizeof(struct udphdr) + offset)) { |
| 4981 | LM_DBG("received small packet: %d. Ignore it\n",len); |
| 4982 | continue; |
| 4983 | } |
| 4984 | |
| 4985 | iph = (struct ip*) (buf + offset); |
| 4986 | |
| 4987 | offset+=iph->ip_hl*4; |
| 4988 | |
| 4989 | udph_start = buf+offset; |
| 4990 | |
| 4991 | udph = (struct udphdr*) udph_start; |
| 4992 | offset +=sizeof(struct udphdr); |
| 4993 | |
| 4994 | if ((buf+offset)>end){ |
| 4995 | continue; |
| 4996 | } |
| 4997 |
no test coverage detected