src/connectivity/network/tests/external_network_test_client.cc
// Test to ensure UDP send doesn`t error even with ARP timeouts.
// TODO(fxb.dev/35006): Test needs to be extended or replicated to test
// against other transport send errors.
Test to ensure UDP send doesn`t error even with ARP timeouts.
TODO(fxb.dev/35006): Test needs to be extended or replicated to test
against other transport send errors.
Test to ensure UDP send doesn ` t error even with ARP timeouts . TODO ( fxb . dev / 35006 ) : Test needs to be extended or replicated to test against other transport send errors .
TEST(ExternalNetworkTest, UDPErrSend) {
  int sendfd;
  ASSERT_GE(sendfd = socket(AF_INET, SOCK_DGRAM, 0), 0) << strerror(errno);
  struct sockaddr_in addr = {};
  addr.sin_family = AF_INET;
  addr.sin_port = htons(1337);
  char bytes[64];
  ssize_t len = sizeof(bytes);
  addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  EXPECT_EQ(sendto(sendfd, bytes, sizeof(bytes), 0, reinterpret_cast<struct sockaddr*>(&addr),
                   sizeof(addr)),
            len)
      << strerror(errno);
  addr.sin_addr.s_addr = htonl(0xd0e0a0d);
  ssize_t ret = sendto(sendfd, bytes, sizeof(bytes), 0, reinterpret_cast<struct sockaddr*>(&addr),
                       sizeof(addr));
#if defined(__linux__)
  EXPECT_EQ(ret, len) << strerror(errno);
#else
  EXPECT_EQ(ret, -1);
  EXPECT_EQ(errno, EHOSTUNREACH) << strerror(errno);
#endif
  addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  EXPECT_EQ(sendto(sendfd, bytes, sizeof(bytes), 0, reinterpret_cast<struct sockaddr*>(&addr),
                   sizeof(addr)),
            len)
      << strerror(errno);
  EXPECT_EQ(close(sendfd), 0) << strerror(errno);
}
TEST ( ExternalNetworkTest , UDPErrSend ) { int sendfd ; ASSERT_GE ( sendfd = socket ( AF_INET , SOCK_DGRAM , 0 ) , 0 ) << strerror ( errno ) ; struct sockaddr_in addr = { } ; addr . sin_family = AF_INET ; addr . sin_port = htons ( 1337 ) ; char bytes [ 64 ] ; ssize_t len = sizeof ( bytes ) ; addr . sin_addr . s_addr = htonl ( INADDR_LOOPBACK ) ; EXPECT_EQ ( sendto ( sendfd , bytes , sizeof ( bytes ) , 0 , reinterpret_cast < struct sockaddr * > ( & addr ) , sizeof ( addr ) ) , len ) << strerror ( errno ) ; addr . sin_addr . s_addr = htonl ( 0xd0e0a0d ) ; ssize_t ret = sendto ( sendfd , bytes , sizeof ( bytes ) , 0 , reinterpret_cast < struct sockaddr * > ( & addr ) , sizeof ( addr ) ) ; #if defined ( __linux__ ) EXPECT_EQ ( ret , len ) << strerror ( errno ) ; #else EXPECT_EQ ( ret , -1 ) ; EXPECT_EQ ( errno , EHOSTUNREACH ) << strerror ( errno ) ; #endif addr . sin_addr . s_addr = htonl ( INADDR_LOOPBACK ) ; EXPECT_EQ ( sendto ( sendfd , bytes , sizeof ( bytes ) , 0 , reinterpret_cast < struct sockaddr * > ( & addr ) , sizeof ( addr ) ) , len ) << strerror ( errno ) ; EXPECT_EQ ( close ( sendfd ) , 0 ) << strerror ( errno ) ; }
Test to ensure UDP send doesn`t error even with ARP timeouts.
Test to ensure UDP send doesn ` t error even with ARP timeouts .
// Assign to a ssize_t variable to avoid compiler warnings for signedness in the EXPECTs below. // Precondition sanity check: write completes without error. // Send to a routable address to a non-existing remote. This triggers ARP resolution which is // expected to fail, but that failure is expected to leave the socket alive. Before the change // that added this test, the socket would be incorrectly shut down. // TODO(tamird): Why does linux not signal an error? Should we do the same? // Postcondition sanity check: write completes without error.