Altera_Forum
Honored Contributor
21 years agoUDP send always fails with -1
Hi,
We have a simple setup running on Altera development board where we are attempting to send a UDP packet out to a PC for collcetion. Starting with the net example files, I was able to build a cut down version of udp_lo_test.c that only sends UDP rather than both send and recieve. A Linux machine running Ethereal has been configured to pick up the outgoing UDP packets. The problem is that when we go to send the UDP packet we get a -1 return from the sendto() method. Looking into the documentation has prooved fruitless as it seems that sendto() responds with -1 on every possible error it produces. This is odd, as an ARP request has been intercepted by the Linux box, possibly indicating that the Altera has attempted to resolve the Linux machines MAC. The NIOS II debugger IDE has not yielded any answers either, all it seems to do is display erratic (yet consistant) behaviour once entering the ECOS library. We are certain that ECOS is set up correctly as we are able to access the ECOS status web bage from the target. Can anyone shed any light on to what we are doing wrong? Our application is included below.//==========================================================================
//
// 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
// Mofified: steve.mann@<stuff>.co.nz
// replace stuff with tait
// Date: 2005-03-12
// Network throughput test code
# include <network.h>
# include <cyg/infra/testcase.h>
# define SOURCE_PORT 9990
# define MAX_BUF 1000
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_client;
static cyg_thread client_thread_data;
static cyg_handle_t client_thread_handle;
# define MAIN_THREAD_PRIORITY CYGPKG_NET_THREAD_PRIORITY-4
/* This looks to be a tidier exit routine than the defailt one.
*/
void
pexit(char *s)
{
CYG_TEST_FAIL_FINISH( s );
}
void client(void)
{
/* Our local stuff.
*/
int s_source; // Socket handle
struct sockaddr_in local; // Address structure
int len; // Seems to hold the return value of the packet send. Quite possibly a lenght indicator.
printf("client:started\n");
/* In most operating systems, network connections are handled much like file streams.
* We request a handle that we can configure and use, and when we are done we can
* call the close method on the handle.
*/
s_source = socket(AF_INET, SOCK_DGRAM, 0);
/* Nothing like a little sanity test on the socket.
* Here, a negative number appears to be an error report.
*/
if (s_source < 0) {
pexit("stream socket");
}
/* This appears to be a structure zeroing procedure.
* I imagine there are other fields in this structure that are not considered by
* this routine and are zeroed to set them to a known default.
*/
memset(&local, 0, sizeof(local));
/* Here, the connection is defined.
*/
local.sin_family = AF_INET;
local.sin_len = sizeof(local);
local.sin_port = htons(SOURCE_PORT);
/* Target address - it is an IP in hex.
* In this particular case, 172.25.110.17 ges to AC.19.6E.11
*/
local.sin_addr.s_addr = htonl(0xAC196E11);
//local.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
//printf("%d \n",connect(s_source, (struct sockaddr *)&local, sizeof(local)));
/* This portion of code appears to be the send routine for the client/
*/
if ( (len= sendto(s_source,data_buf_write,sizeof(data_buf_write),
0,(struct sockaddr *)&local,sizeof(local))) < 0 ) {
printf("%d\n", len);
CYG_TEST_FAIL_FINISH("Error writing buffer");
}
/* When we are done, it is good karma to deal woith our allcoated socket.
*/
close(s_source);
}
void
udp_client(cyg_addrword_t param)
{
printf("Start UDP client - test\n");
# if NLOOP > 0
client();
# endif
}
void
cyg_start(void)
{
CYG_TEST_INIT();
printf("UDP blit test - How much data can we pull?\n");
while(1)
client();
}