lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] lwip bind fail


From: Jin Won Seo
Subject: [lwip-users] lwip bind fail
Date: Thu, 19 Sep 2013 11:19:27 -0700

Hi all,

I posted my issue but I fell like not describing the problem in detail. So I re-post it with detail information.

I am testing listener modules using LM3S9B96, lwip1.3.2, safeRTOS, StellarisWare 10636, ccs 5.4.x.

The listener task running on safeRTOS basically receives message from server daemon in Unix using socket(UDP).

As the server daemon sends messages, the listener seems like not getting anything from the server

Also I directly attempts to access the listener using telnet command(telnet 192.2.0.208 5701), but the below error message comes out

"telnet : Unable to connect to remote host: Connection refused"

My test scenario is :

1. Get an IP from Server(Unix) using DHCP

    //
    // Initialize lwIP.
    //
    lwIPInit(pucMAC, 0, 0, 0, IPADDR_USE_DHCP);

    //
    // Setup the remaining services inside the TCP/IP thread's context.
    //
    tcpip_callback(SetupServices, 0);

2. Init lwip socket in SetupServices().

lwip_socket_init();

3. Create listener task to receive packets from server daemon(UDP).

    int socket_fd;
    struct sockaddr_in sa, ra;//sa = sender addr, ra= receiver addr
    NET_MSG *sMsg;
    int length;

    u32_t size;
    size = sizeof(sa);

//    addr_setup();
//    portTickType xTime1, xTime2;

    // Setup the local address.
    memset((char *) &ra, 0, sizeof(ra));
    ra.sin_family = AF_INET;
    ra.sin_len = sizeof(ra);
//    ra.sin_addr.s_addr = lwIPLocalIPAddrGet();
    ra.sin_addr.s_addr = inet_addr("192.2.0.208");
    ra.sin_port = htons(S_PORT);//#define S_PORT 5701

    //setup the destination address
    memset((char *) &sa, 0, sizeof(sa));
    sa.sin_family = AF_INET;
    sa.sin_len = sizeof(sa);
    sa.sin_addr.s_addr = inet_addr("192.2.0.3");// for test, hard-corded
//    sDestAddr.sin_addr.s_addr = chgd_in_addr();
    sa.sin_port = htons(S_PORT);

    while((socket_fd = lwip_socket(AF_INET, SOCK_DGRAM, 0)) == 0)
    {
        DisplayString(115, 210 - 10, "  lwip socket error...  ");
        //xTaskDelay(CHGD_OPEN_TIME);
        xTaskDelay(SECONDS(5));//arbitrary time for test
    }

    //bind socket to the local address and port
    if(lwip_bind(socket_fd, (struct sockaddr *) &ra, sizeof(ra)) == -1)
    {
        lwip_close(socket_fd);
        DisplayString(115, 190 - 10, "  bind error...  ");//Display message on LCD in LM3S9B96
    }

    while(1)
    {

        //receive from server
        length = lwip_recvfrom(socket_fd, (char *) msg_buf, sizeof(msg_buf),
                MSG_DONTWAIT, (struct sockaddr *)&sa, &size);

        if(length > 0)
        {
            sMsg = (NET_MSG *) (msg_buf);
            mon_cmd_do(socket_fd, &sa, sMsg, length);
        }

        lwip_close(socket_fd);
        xTaskDelay(1);// 1ms tick delay
    }


As the program is executed, it seems like not binding socket properly since "bind error..." is displayed on LCD.

Here is my lwipopts.h

#define SYS_LIGHTWEIGHT_PROT            1           // default is 0
#define NO_SYS                          0           // default is 0
#if !NO_SYS
#define RTOS_SAFERTOS                   1
#define RTOS_FREERTOS                   0
#endif /* !NO_SYS */

#define MEMP_NUM_PBUF                   64 
#define MEMP_NUM_TCP_PCB                40   
#define MEMP_NUM_TCP_SEG                48 
#define MEMP_NUM_SYS_TIMEOUT            10
#define PBUF_POOL_SIZE                  64   

#define IP_REASSEMBLY                   0           // default is 1
#define IP_FRAG                         0           // default is 1

#define LWIP_DHCP                       1

#define LWIP_AUTOIP                     1           // default is 0
#define LWIP_DHCP_AUTOIP_COOP           ((LWIP_DHCP) && (LWIP_AUTOIP))
                                                    // default is 0
#define LWIP_DHCP_AUTOIP_COOP_TRIES     5           // default is 9


#define TCP_WND                         4096   // default is 2048
#define TCP_MSS                        1500        // default is 128
//#define TCP_CALCULATE_EFF_SEND_MSS      1
#define TCP_SND_BUF                     (6 * TCP_MSS)
                                                    // default is 256
#define TCP_SND_QUEUELEN                (MEMP_NUM_TCP_SEG)

#define PBUF_LINK_HLEN                  16          // default is 14
#define PBUF_POOL_BUFSIZE               256
                                                    // default is LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_HLEN)
#define ETH_PAD_SIZE                    2           // default is 0

#define TCPIP_THREAD_NAME              "tcpip_thread"
#define TCPIP_THREAD_STACKSIZE          1024
#define TCPIP_THREAD_PRIO               3
#define TCPIP_MBOX_SIZE                 32

#define LWIP_NETCONN                    1           // default is 1

//*****************************************************************************
//
// ---------- Socket Options ----------
//
//*****************************************************************************
#define LWIP_SOCKET                     1           // default is 1
#define LWIP_COMPAT_SOCKETS             0
#define LWIP_POSIX_SOCKETS_IO_NAMES     0
#define LWIP_TCP_KEEPALIVE              0
#define LWIP_SO_RCVTIMEO                0
#define LWIP_SO_RCVBUF                  0
#define SO_REUSE                        0

#define LWIP_PROVIDE_ERRNO              1            //Add for lwip socket errors

#define LWIP_STATS_LARGE                  1

#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_OFF

#define LWIP_DBG_TYPES_ON               (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH)

So far I don't see any clues to figure this out.

If anyone can help me out, I will appreciate that.

Thank,

Jin


reply via email to

[Prev in Thread] Current Thread [Next in Thread]