i have embed a tiny dns in ESP8266 (using RTOS SDK)
but when runing the ESP8266, it was always put out something strange code to UART0
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x40100000, len 30140, room 16
tail 12
chksum 0x6d
ho 0 tail 12 room 4
load 0x3ffe8000, len 1148, room 12
tail 0
chksum 0x10
load 0x3ffe8480, len 784, room 8
tail 8
chksum 0x89
csum 0x89
劽諄MEM CHECK FAIL!!!
my dns code is like below:
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "Tinydns.h"
#include <lwip/sockets.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#define PORT 53
#define MSG_SIZE 256
void TinydnsTask(void *pvParameters)
{
struct sockaddr_in addr, server;
char *msg = (char *)malloc(MSG_SIZE);
// socket creation
int sd = socket(AF_INET, SOCK_DGRAM, 0);
if (sd < 0) {
//printf(stderr, "%s: cannot open socket \n", argv[0]);
//return 1;
asm("break 1,1");
}
printf("TinyDns open socket \n" );
// bind local server port
server.sin_family = AF_INET;
server.sin_addr.s_addr = htonl(INADDR_ANY);
server.sin_port = htons(PORT);
int rc = bind(sd, (struct sockaddr *) &server, sizeof(server));
if (rc < 0) {
//fprintf(stderr,"%s: cannot bind port number %d \n", argv[0],PORT);
//return 1;
asm("break 1,1");
}
printf("TinyDns Bind socket \n");
socklen_t len = sizeof(addr);
int flags = 0;
//int RxTimeout = 1000;
while (1) {
//int ret = setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, &RxTimeout, sizeof(int));
// receive message
int n = recvfrom(sd, msg, MSG_SIZE, flags, (struct sockaddr*)&addr, &len);
//int n = -1;
//vTaskDelay(1000);
if (n <= 0) {continue;}
printf("TinyDns recive msg : %d byte from socket \n",n);
// Same Id
msg[2] = 0x81; msg[3] = 0x80; // Change Opcode and flags
msg[6] = 0; msg[7] = 1; // One answer
msg[8] = 0; msg[9] = 0; // NSCOUNT
msg[10] = 0; msg[11] = 0; // ARCOUNT
// Keep request in message and add answer
msg[n++] = 0xC0; msg[n++] = 0x0C; // Offset to the domain name
msg[n++] = 0x00; msg[n++] = 0x01; // Type 1
msg[n++] = 0x00; msg[n++] = 0x01; // Class 1
msg[n++] = 0x00; msg[n++] = 0x00; msg[n++] = 0x00; msg[n++] = 0x3c; // TTL
msg[n++] = 0x00; msg[n++] = 0x04; // Size --> 4
msg[n++] = 0x12; msg[n++] = 0x34; msg[n++] = 0x56; msg[n++] = 0x78; // IP
// Send the answer
sendto(sd, msg, n, flags, (struct sockaddr *)&addr, len);
if (msg){
free(msg);
msg = NULL;
printf("free msg \n");
}
}
//return 0;
}
and i create a task in user_init() like that :
xTaskCreate(TinydnsTask, (signed char *)"Mdns", 256, NULL, 2, NULL);
does anybody know what is wrong????