This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem Establishing socket Connection


On Mon, Nov 10, 2003 at 11:12:30AM -0700, kevin_lemay@agilent.com wrote:

> I am trying to port some working vxWorks code over the eCos. This
> includes some standard BSD socket connections.

> I am encountering a problem within eCos. It has decided that I am
> trying to establish a network connection to a multicast socket,
> which is not the case.
> 
> We are attempting to connect to 130.30.174.109 (x821eae6d), port 5678.
> 
> I am using the CVS version of eCos as of Friday on an i386 platform.

It always a good idea to post a complete (none)working test
case. Something we can just compile and run. It saves us time messing
turning your code fragment into something useful.

I've attached what i used to test this.

> 
> The error occurs in tcp_usrrec.c at line 341
> 
> 
>  	336		/*
>  	337		 * Must disallow TCP ``connections'' to multicast addresses.
>  	338		 */
>  	339		sinp = (struct sockaddr_in *)nam;
> -	340		if (sinp->sin_family == AF_INET
> -	341		    && IN_MULTICAST(ntohl(sinp->sin_addr.s_addr))) {
> -	342			error = EAFNOSUPPORT;
> -	343			goto out;
>  	344		}

I get another error. EINVAL. I didn't track it down, but these seems
much more reasonable to me than EAFNOSUPPORT.

Please try to reproduce your problem either using my code, or build a
complete test case which demonstrates the problem.

         Thanks
                Andrew
#include <network.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include <cyg/infra/testcase.h>

#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x10000)
static char stack[STACK_SIZE];
static cyg_thread thread_data;
static cyg_handle_t thread_handle;

int yourtest(void) 
{
  
   int rc;
    struct sockaddr_in servAddr;
    int socketId;
    char * srvIpAddress = "130.30.174.109";
    int port = 5297;
    
    /* Server side */
    bzero(&servAddr, sizeof(servAddr));
    servAddr.sin_family = AF_INET;
    inet_aton(srvIpAddress, &servAddr.sin_addr);
    servAddr.sin_port = htons(port);
                                                                                                    
    /* create socket */
    socketId = socket(AF_INET, SOCK_STREAM, 0);
                                                                                                    
    if (socketId < 0)
    {
        return( -1 );
    }
                                                                                                    
    /* connect to server */
    rc = connect(socketId, (struct sockaddr *) &servAddr, sizeof(servAddr));
    if (rc<0)
    {
        close(socketId);
        socketId = 0;
        perror("connect");
        return(-1);
    }
    return(socketId);
    
}

void myfunc(cyg_addrword_t data)
{
                                                                                        
  init_all_network_interfaces();
  
  yourtest();
}

void
cyg_start(void)
{
    CYG_TEST_INIT();

    cyg_thread_create(3,                        // Priority
                      myfunc,                   // entry
                      0,                        // entry parameter
                      "Test program",           // Name
                      &stack[0],                // Stack
                      STACK_SIZE,               // Size
                      &thread_handle,           // Handle
                      &thread_data              // Thread data structure
            );
    cyg_thread_resume(thread_handle);    // Start it

    cyg_scheduler_start();
}



-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]