Forum Discussion
Altera_Forum
Honored Contributor
21 years agoHi,
I've made progress today, I've managed to get things so that sendto does not fail. To do this I added init_all_network_interfaces() into CYG_START, and that seemed to cure things. I'm using a hub to connect to the PC (to avoid any probs the network may cause), and all that results is that one ARP goes across to the PC, which acknowledges it and sends it out (Ethereal readout looks fine). You can see the green LED on the NIOS-eval_board flash each time, and there after there is no activity. Even though the client is run multiple times and reports its sent the entire data_buffer. I've included the code I'm currently using and the console readout below. I guess I need to figure out why things go dead after the ARP, but don't know where to start (really am a novice at all this)!//==========================================================================
//
// tests/udp_lo_test.c
//
// Simple UDP throughput test
//
//==========================================================================
//####BSDCOPYRIGHTBEGIN####
//
// -------------------------------------------
//
// Portions of this software may have been derived from OpenBSD or other sources
// and are covered by the appropriate copyright disclaimers included herein.
//
// -------------------------------------------
//
//####BSDCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): sorin@netappi.com
// Contributors: gthomas,sorin@netappi.com, hmt
// Date: 2000-05-24
// Network throughput test code
# include <network.h># include <errno.h>
# include <cyg/infra/testcase.h>
# define SOURCE_PORT 9990# define SINK_PORT 9991
# define NUM_BUF 1024# define MAX_BUF 8192
static unsigned char data_buf;
static unsigned char data_buf_write="Client UDP is alive. You may continue ....";
# define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x10000)
static char stack_server;
static cyg_thread server_thread_data;
static cyg_handle_t server_thread_handle;
static char stack_client;
static cyg_thread client_thread_data;
static cyg_handle_t client_thread_handle;
# define MAIN_THREAD_PRIORITY CYGPKG_NET_THREAD_PRIORITY-4
void
pexit(char *s)
{
CYG_TEST_FAIL_FINISH( s );
}
void client(void)
{
int s_source;
struct sockaddr_in local;
int len;
printf("client:started\n");
s_source = socket(AF_INET, SOCK_DGRAM, 0);
if (s_source < 0) {
pexit("stream socket");
}
memset(&local, 0, sizeof(local));
local.sin_family = AF_INET;
local.sin_len = sizeof(local);
local.sin_port = htons(SOURCE_PORT);
local.sin_addr.s_addr = inet_addr ("172.25.110.17");
// local.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
if ( (len= sendto(s_source,data_buf_write,sizeof(data_buf_write),
0,(struct sockaddr *)&local,sizeof(local))) < 0 ) {
diag_printf("error = %d\n",errno);
CYG_TEST_FAIL_FINISH("Error writing buffer");
}
printf("Length Sent %d\n",len);
close(s_source);
}
void
udp_server(cyg_addrword_t param)
{
init_all_network_interfaces();
diag_printf("Start UDP server - test\n");
cyg_thread_resume(client_thread_handle); // Start the other one# if NLOOP > 0
server();
CYG_TEST_PASS_FINISH("Server returned OK");# endif
CYG_TEST_NA( "No loopback devs" );
}
void
udp_client(cyg_addrword_t param)
{
diag_printf("Start UDP client - test\n");# if NLOOP > 0
client(); # endif
}
void
cyg_start(void)
{
//CYG_TEST_INIT();
init_all_network_interfaces();
while(1)
client();
} Console ... [cyg_net_init] Init: mbinit(0x00000000) [cyg_net_init] Init: cyg_net_init_devs(0x00000000) Init device 'lan91c111_eth0' [cyg_net_init] Init: loopattach(0x00000000) [cyg_net_init] Init: ifinit(0x00000000) [cyg_net_init] Init: domaininit(0x00000000) [cyg_net_init] Init: cyg_net_add_domain(0x0105e55c) New domain internet at 0x00000000 [cyg_net_init] Init: cyg_net_add_domain(0x0105deb0) New domain route at 0x00000000 [cyg_net_init] Init: call_route_init(0x00000000) [cyg_net_init] Done BOOTP[eth0] op: REPLY htype: Ethernet hlen: 6 hops: 0 xid: 0x0 secs: 0 flags: 0x0 hw_addr: 00:07:ed:0b:05:26 client IP: 172.25.106.77 my IP: 172.25.106.77 server IP: 172.25.112.64 gateway IP: 172.25.2.251 options: subnet mask: 255.255.0.0 IP broadcast: 172.25.2.251 gateway: 172.25.2.251 [eth_drv_ioctl] Warning: Driver can't set multi-cast mode [eth_drv_ioctl] Warning: Driver can't set multi-cast mode [eth_drv_ioctl] Warning: Driver can't set multi-cast mode client:started Length Sent 8192 client:started Length Sent 8192 client:started