lwIP - TCP/IP Stack

Gast #1486000
Lesenswert?

Hallo, hat hier jemand Erfahrung mit dem Stack lwip?
Auf einem Mikrcrocontroller läuft der lwip Stack. Das versenden von 
UDP-Packeten an meinen PC funktioniert. Nur der Empfang von UDP-Packeten 
vom PC zum Mikrocontroller funktioniert nicht.
1
void main (void)
2
{
3
   ..............
4
   while(1)
5
   {
6
      recvUDP();
7
   }
8
}
9

10
void udp_echo_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
11
{
12
  if (p != NULL) 
13
  {
14
    udp_sendto(pcb, p, addr, port)/    
15
    pbuf_free(p);
16
  }
17
}
18

19
void recvUDP(void)
20
{
21
    char buffer[1024];
22
    err_t retval;  
23
    struct ip_addr ipaddr;
24
    struct udp_pcb *pcb;
25
    struct pbuf *pb;
26
    IP4_ADDR(&ipaddr, 192,167,1,7); // IP vom PC
27
    pcb = udp_new();
28
    retval = udp_bind(pcb, IP_ADDR_ANY, 2222);
29
    
30
    udp_connect(pcb, &ipaddr, 2222);
31
    udp_recv(pcb, udp_echo_recv, NULL);
32
}

Vielleiccht sollte ich mal auf der Ethernet Schicht mal nachschauen ob 
überhaupt was am Mikrocontroller ankommt. Weiss allerdings nicht wo ich 
da
eingreifen müsste.
Gast #1515505
Lesenswert?

a) There is a mailing list for lwip users, where this question might be 
better off: http://savannah.nongnu.org/mail/?group=lwip

b) The problem might be that the struct ip_addr pointer points into the 
pbuf at the place of the 'from' address in the IP header. At the time 
the IP layer tries to send the packet, that 'from' address contains your 
local IP address. Try to copy the ip address to a local address on the 
stack:

struct ip_addr addr2;
addr2.addr = addr->addr;
udp_sendto(pcb, p, &addr2, port);

That might work.
Simon

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren