Esempio n. 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);
}
Esempio n. 2
0
static void
sender (const char *ip, const int port, const char *iface)
{
  LWES_BYTE buffer[500];
  struct lwes_net_connection connection;
  unsigned int i;

  /* 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*)ip,
                          (char*)iface,
                          (int)port) == 0 );

  for ( i = 0 ; i < num_to_send; i++ )
    {
      assert ( lwes_net_send_bytes (&connection,buffer,45) > 0 );
    }

  lwes_net_close (&connection);
}
Esempio n. 3
0
int
lwes_net_sendto_bytes
  (struct lwes_net_connection *conn,
   char *address,
   char *iface,
   int port,
   LWES_BYTE_P bytes,
   size_t len)
{
  struct lwes_net_connection new_conn;
  int size;

  if (conn == NULL || bytes == NULL)
    {
      return -1;
    }

  if (lwes_net_open (&new_conn, address, iface, port) < 0)
    {
      return -2;
    }

  if ((size = lwes_net_send_bytes (&new_conn, bytes, len)) < 0)
    {
      return -3;
    }

  /* There's not much we can do about a close error, and it would mask a
     successful send, so just ignore a bad return value */
  (void) lwes_net_close (&new_conn);

  return size;
}
int
my_lwes_net_send_bytes
  (struct lwes_net_connection *conn,
   LWES_BYTE_P bytes,
   size_t len)
{
  if (lwes_net_send_bytes_error == 0)
    {
      return lwes_net_send_bytes (conn, bytes, len);
    }
  return -1;
}
Esempio n. 5
0
static void 
test_large_send ()
{
  struct lwes_net_connection connection;
  unsigned int i;
  LWES_BYTE buffer [MAX_MSG_SIZE];

  for (i=0; i < MAX_MSG_SIZE; i++)
    {
      buffer[i] = (LWES_BYTE) i;
    }

  assert ( lwes_net_open (&connection,
                          (char *)mcast_ip,
                          (char *)mcast_iface,
                          (int)mcast_port)
           == 0 );
  assert ( lwes_net_send_bytes (&connection, buffer, MAX_MSG_SIZE)  > 0); 
  lwes_net_close (&connection);  
}