Beispiel #1
0
static void test_null_args (void)
{
  LWES_BYTE buffer[500];
  unsigned int i;
  struct lwes_net_connection connection;

  /* initialize to nothing */
  for (i = 0; i < 500; i++)
    buffer[i]=(LWES_BYTE)0;

  /* now set 45 bytes */
  for (i = 0; i < 45; i++)
    {
      buffer[i]=(LWES_BYTE)i;
    }


  /* test NULL connection to all calls */

  assert (lwes_net_open (NULL, 
                         (char*)mcast_ip,
                         (char*)mcast_iface,
                         (int)mcast_port) == -1);
  assert (lwes_net_close (NULL) == -1);

  assert (lwes_net_get_ttl (NULL) == -1);

  assert (lwes_net_set_ttl (NULL, 5) == -1);

  assert (lwes_net_get_sock_fd (NULL) == -1);

  assert (lwes_net_send_bytes (NULL, buffer, 45) == -1);
  assert (lwes_net_send_bytes (&connection, NULL, 45) == -1);

  assert (lwes_net_sendto_bytes (NULL,
                                 (char*)mcast_ip,
                                 (char*)mcast_iface,
                                 (int)mcast_port,
                                 buffer,
                                 45) == -1);

  assert (lwes_net_sendto_bytes (&connection,
                                 (char*)mcast_ip,
                                 (char*)mcast_iface,
                                 (int)mcast_port,
                                 NULL,
                                 45) == -1);

  assert (lwes_net_recv_bind (NULL) == -1);

  assert (lwes_net_recv_bytes (NULL, buffer, 500) == -1);
  assert (lwes_net_recv_bytes (&connection, NULL, 500) == -1);

  assert (lwes_net_recv_bytes_by (NULL, buffer, 500, 10000) == -1);
  assert (lwes_net_recv_bytes_by (&connection, NULL, 500, 10000) == -1);
}
Beispiel #2
0
static void
sender_to (const char *ip, const int port, const char *iface)
{
  LWES_BYTE buffer[500];
  struct lwes_net_connection connection;
  unsigned int i;
  int new_port = port+1;

  /* freebsd seems to bail on setsockopt for the interface if we
     have a null address, so test with two real addresses */
  char hostname[500];
  char ipaddr[500];
  struct hostent *hptr;
  assert (gethostname (hostname, 500) == 0);
  assert ((hptr = gethostbyname (hostname)) != NULL);
  switch (hptr->h_addrtype)
    {
      case AF_INET:
        {
          char **pptr;
          pptr = hptr->h_addr_list;
          inet_ntop (hptr->h_addrtype, *pptr, ipaddr, 500);
        }
        break;
    }

  /* initialize to nothing */
  for (i = 0; i < 500; i++)
    buffer[i]=(LWES_BYTE)0;

  /* now set 45 bytes */
  for (i = 0; i < 45; i++)
    {
      buffer[i]=(LWES_BYTE)i;
    }

  /* open up on the null interface, but sendto a different interface */
  assert ( lwes_net_open (&connection,
                          (char*)ip,
                          (char*)ipaddr,
                          (int)port) == 0 );

  for ( i = 0 ; i < num_to_send; i++ )
    {
      assert (lwes_net_sendto_bytes (&connection,
                                     (char*)ip,
                                     (char*)iface,
                                     (int)new_port,
                                     buffer,45) > 0);
    }

  lwes_net_close (&connection);
}
int
my_lwes_net_sendto_bytes
  (struct lwes_net_connection *conn,
   char *address,
   char *iface,
   int port,
   LWES_BYTE_P bytes,
   size_t len)
{
  if (lwes_net_sendto_bytes_error == 0)
    {
      return lwes_net_sendto_bytes (conn, address, iface, port, bytes, len);
    }
  return -1;
}
Beispiel #4
0
static void
test_sendto_bytes_failures (void)
{
  LWES_BYTE buffer[500];
  struct lwes_net_connection connection;
  unsigned int i;
  int new_port = mcast_port+1;

  /* freebsd seems to bail on setsockopt for the interface if we
     have a null address, so test with two real addresses */
  char hostname[500];
  char ipaddr[500];
  struct hostent *hptr;
  assert (gethostname (hostname, 500) == 0);
  assert ((hptr = gethostbyname (hostname)) != NULL);
  switch (hptr->h_addrtype)
    {
      case AF_INET:
        {
          char **pptr;
          pptr = hptr->h_addr_list;
          inet_ntop (hptr->h_addrtype, *pptr, ipaddr, 500);
        }
        break;
    }

  /* initialize to nothing */
  for (i = 0; i < 500; i++)
    buffer[i]=(LWES_BYTE)0;

  /* now set 45 bytes */
  for (i = 0; i < 45; i++)
    {
      buffer[i]=(LWES_BYTE)i;
    }

  assert (lwes_net_open (&connection,
                         (char*)mcast_ip,
                         (char*)mcast_iface,
                         (int)mcast_port) == 0);

  /* lwes_net_open failure */
  socket_error = 1;
  assert (lwes_net_sendto_bytes (&connection,
                                 (char*)mcast_ip,
                                 (char*)ipaddr,
                                 (int)new_port,
                                 buffer,45) == -2);
  socket_error = 0;

  /* lwes_net_send_bytes failure */
  sendto_error = 1;
  assert (lwes_net_sendto_bytes (&connection,
                                 (char*)mcast_ip,
                                 (char*)ipaddr,
                                 (int)new_port,
                                 buffer,45) == -3);
  sendto_error = 0;

  assert (lwes_net_close (&connection) == 0);
}