ESP8266 Developer Zone The Official ESP8266 Forum 2015-11-01T17:35:47+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=1233 2015-11-01T17:35:47+08:00 2015-11-01T17:35:47+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1233&p=4401#p4401 <![CDATA[Re: Recognize UDP Broadcast]]> Statistics: Posted by eriksl — Sun Nov 01, 2015 5:35 pm


]]>
2015-10-26T21:16:11+08:00 2015-10-26T21:16:11+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1233&p=4282#p4282 <![CDATA[Re: Recognize UDP Broadcast]]> 1. when reading the SDK 1.4 documentation I found no hint how to access the MAC layer of an incoming UDP-packet/datagram
2. network + broadcast addresses are known for sure - but the requirement is to know if the broadcast address had been used by foreign sender

Statistics: Posted by tomboli — Mon Oct 26, 2015 9:16 pm


]]>
2015-10-26T02:21:23+08:00 2015-10-26T02:21:23+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1233&p=4262#p4262 <![CDATA[Re: Recognize UDP Broadcast]]>
- check MAC layer broadcast address, but you need access to the MAC layer for that (WLAN frame)
- if you know the ip address AND the netmask, you can assume the first and the last addresses in the range are broadcast/net.

AFAIK you can inquire the destination address for an UDP packet.

Statistics: Posted by eriksl — Mon Oct 26, 2015 2:21 am


]]>
2015-10-22T16:04:25+08:00 2015-10-22T16:04:25+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1233&p=4237#p4237 <![CDATA[Re: Recognize UDP Broadcast]]> espconn_get_connection_info() gets the sender address which is needed for example for a response as you showed in your example
We wanted to solve another issue:
The ESP device can be addressed by its IP or by a broadcast address - I didn't find any way to distinguish that!
Example:
remote device with 192.168.4.50 sends an udp packet to ESP device having the 192.168.4.1 optionally in 2 ways:
1. 192.168.4.50 sends to 192.168.4.1
2. 192.168.4.50 sends to 192.168.4.255
In both cases ESP receives the packet well and can respond to 192.168.4.50. The problem is to see if it was addressed via 192.168.4.1 or 192.168.4.255.
The requirement is to send a response only if it was addressed direct but not via broadcast! Today we solved that with a flag within the payload. This requires that all callers do this correct which may not be in our response an so far is not satisfying.

Statistics: Posted by tomboli — Thu Oct 22, 2015 4:04 pm


]]>
2015-10-16T10:17:42+08:00 2015-10-16T10:17:42+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1233&p=4128#p4128 <![CDATA[Re: Recognize UDP Broadcast]]>
Here a sample code:

Code:

LOCAL void ICACHE_FLASH_ATTR
 user_udp_recv_cb(void *arg, char *pusrdata, unsigned short length)
 {
     os_printf("recv udp data: %s\n", pusrdata);
     struct espconn *pesp_conn = arg;
     
       remot_info *premot = NULL;
       sint8 value = ESPCONN_OK;
       if (espconn_get_connection_info(pesp_conn,&premot,0) == ESPCONN_OK){
          char *pbuf = "udp_sent\n";
             pesp_conn->proto.tcp->remote_port = premot->remote_port;
             pesp_conn->proto.tcp->remote_ip[0] = premot->remote_ip[0];
             pesp_conn->proto.tcp->remote_ip[1] = premot->remote_ip[1];
             pesp_conn->proto.tcp->remote_ip[2] = premot->remote_ip[2];
             pesp_conn->proto.tcp->remote_ip[3] = premot->remote_ip[3];
             espconn_send(pesp_conn, pusrdata, os_strlen(pusrdata));
       }
 }

Statistics: Posted by ESP_Faye — Fri Oct 16, 2015 10:17 am


]]>
2015-10-15T15:53:02+08:00 2015-10-15T15:53:02+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1233&p=4114#p4114 <![CDATA[Recognize UDP Broadcast]]> it seems that there is no possibility to detect if the device has been addressed by a broadcast.

Code:

LOCAL struct espconn    udpconn;        // udp server

void user_devicefind_recv(void *arg, char *data, unsigned short data_len) {

    struct espconn          *pConnection = (struct espconn*)arg;
    remot_info              *premot = NULL;

   espconn_get_connection_info(pConnection, &premot, 0);  // get sender data (source IP)
   os_memcpy(udpconn.proto.udp->remote_ip, premot->remote_ip, 4);
   udpconn.proto.udp->remote_port = premot->remote_port;

   debug("UDP remote: " IPSTR ":%d\n",  IP2STR(udpconn.proto.udp->remote_ip), udpconn.proto.udp->remote_port);
   // shows correct source IP
   
   debug("UDP local:  " IPSTR ":%d\n",  IP2STR(pConnection->proto.udp->local_ip), pConnection->proto.udp->local_port);
   // shows always the current device IP; never a broadcast address
}


Any hints?

Thanks a lot

Statistics: Posted by tomboli — Thu Oct 15, 2015 3:53 pm


]]>