No announcement yet.

UDP sendto() using MSG_DONTROUTE

  • Filter
  • Time
  • Show
Clear All
new posts

  • UDP sendto() using MSG_DONTROUTE

    Environment: XPort Pro with Evolution OS (V5.4.0.2 R5) and a custom application (without the Lantronix web frontend).

    I want to create an application that responds to a UDP broadcast just like the query port does. Here an example with is the IP address of the PC and is the IP address of the XPP:
    PC -> XPP: UDP ->
    XPP -> PC: UDP ->

    PC and XPP are in the same physical network, but within different subnets. My code works if the XPP has no default gateway. When the XPP has a default gateway, it always tries to send the answer to the gateway, although I use the MSG_DONTROUTE flag.

    What am I doing wrong?

    Here is some of the code (shortened):

    static int s;
    void init(void) // gets called once
      struct sockaddr_in addrIn;
      s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
      // bind socket to query port
      memzero(addrIn, sizeof(addrIn));
      addrIn.sin_family = AF_INET;
      addrIn.sin_port = htons(QUERY_PORT);
      addrIn.sin_addr.s_addr = htonl(INADDR_ANY);
      bind(s, (struct sockaddr *) &addrIn, sizeof(addrIn));  // -> returns 0x0
      // set socket to non-blocking mode
      int socketMode = 1;
      ioctlsocket(s, FIONBIO, &socketMode);
    void loop(void) // gets called periodically
      const char
      int fromLen;
      struct sockaddr srcAddr;
      // try to read one datagram
      fromLen = sizeof(srcAddr);
      if (recvfrom(s, &rx[0], sizeof(rx), 0, &srcAddr, &fromLen) > 0)
      { // request received: send answer
        sendto(s, "ANSWER", strlen("ANSWER"), MSG_DONTROUTE, &srcAddr, fromLen);  // -> returns >= 0

  • #2
    Some more information: Scanning the XPort Pro (V5.4.0.2 R5) in a different subnet (but same physical network) with DeviceInstaller by "query port" does not work, when gateway is not responding. It works with XPort-05, because the query port answer is sent directly to the origin MAC.