int dns_health_check(char *server_ip, char *domain, char *type, char *proto, char *port) { int offset; int result; result = parameter_check(domain, type, proto, port, server_ip); if (result == -1) { return PARAMETER_ERROR; } char sendbuf[BUFFER_MAX_SIZE]; unsigned char recv_buf[BUFFER_MAX_SIZE]; memset(sendbuf, 0, sizeof(sendbuf)); memset(recv_buf,0, sizeof(recv_buf)); offset = gen_dns_packet(sendbuf, domain, type, proto); result = get_dns_response(sendbuf, recv_buf, offset, proto, port, server_ip); if (result != DNS_CHECK_SUCCESS) { return result; } result = unpacket(recv_buf, proto, type); return result; }
/* * @brief 从循环队列中取出一段完整的数据包 */ int get_message_from_lq(Cqueue *Q, unsigned char *desc){ char temp; int count = 0; int len = 0, n;; while(Q->count && Q->base[Q->front] != HEAD){ //取得包头 Q->front = (Q->front + 1) % Q->maxsize; //不是包头的话就丢弃 Q->count--; } count = 1; while(Q->count && (count + 1 <= Q->count) && (temp = Q->base[(Q->front + count)%Q->maxsize]) != END){ //取得包尾 if(temp == HEAD){ Q->front = (Q->front + count) % Q->maxsize; Q->count -= count; count = 1; continue; }else count++; } if(count + 1 <= Q->count){ //队列有完整的数据包完整 if((n = (Q->maxsize - Q->front)) >= (count + 1)){ len = unpacket(desc,&Q->base[Q->front], count+1); //这边也必须谨防数据回到头部 } else{ unsigned char *temp_data; /*存放循环队列中的一段数据*/ temp_data = (unsigned char *)malloc(sizeof(unsigned char) * (count+1)); memcpy(temp_data, Q->base + Q->front, n); memcpy(temp_data + n, Q->base, count + 1 - n); len = unpacket(desc, temp_data, count+1); free(temp_data); } PopupnQueue(Q ,count + 1); } return len; }