Please see this
----- Original Message -----
Sent: Tuesday, August 29, 2006 12:00 PM
Subject: Re: [lwip-users] "minimal" on unix

Thanks for replying.
I tried using tcp_connect(), with a local IP address and the same port on which the server is listening.  The tcp_connect() returned but a connection with the server was not established and the callback for tcp_connect() was never called. 
I also tried connecting using standard socket library connect.  Please help me reach the correct implementation. 
I am also new to networking, please point out any mistake in my testing.  Do you or anyone else have a sample tcp client implementation?

Currently echo.c does not seem to have it's own low_level_xxx functions.  So I was wondering whether tcp_xxx calls use a default network interface when low_level_xxx functions are not provided?

Thanks and regards,
Yadnesh

On 8/29/06, Mumtaz Ahmad <[EMAIL PROTECTED]> wrote:
Dear yadnesh
 
tcp_accept would get called if some client tries to connect on a listening port .Just pingining does not trigger tcp module .
Your second query is not clear .There is always a need of some ethernet driver to actually send the data physically on cable. So low_level_xxx functions need to be implemented
 
Ahmad
 
----- Original Message -----
Sent: Tuesday, August 29, 2006 9:52 AM
Subject: [lwip-users] "minimal" on unix

Hi All,

I am working on Linux and have just started learning about lwIP functionality.  So, studying the example ..../contrib/ports/unix/proj/minimal

There seem to be 2 different types of implementation examples provided.
1) using echo.c
    In this tcp_new(), tcp_bind(), and tcp_accept() are used. 
    I am really confused about working of this implementation.  tcp_accept() has specified echo_accept() as a callback function for all packets received over the network interface.  But echo_accept() never seems to be called when I ping the IP address. 
Could somebody please give me some pointers about what is happening here and whether I am doing something wrong?

2) using mintapif.c
    This works perfectly fine for replying to ping. 
I have the following doubts:
1) Does lwIP communicate directly over the Ethernet "eth0"?  or the "tap" driver is always required?
2) Is it mandatory for all applications to write code for low_level_init(), low_level_input(), and low_level_output() ?

Thanks and Regards,
Yadnesh Phadke


--
This message has been scanned for viruses and
dangerous content by Streaming Networks, and is
believed to be clean.


_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users


--
This message has been scanned for viruses and
dangerous content by
Streaming Networks, and is
believed to be clean.

_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users



--
This message has been scanned for viruses and
dangerous content by
Streaming Networks, and is
believed to be clean.


_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users

--
This message has been scanned for viruses and
dangerous content by Streaming Networks, and is
believed to be clean.
/*
 * Copyright (c) 2001,2002 Florian Schulze.
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the authors nor the names of the contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * test.c - This file is part of lwIPtest
 *
 */

#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#include <string.h>
#include <conio.h>

#include "lwip/debug.h"
#include "lwip/mem.h"
#include "lwip/memp.h"
#include "lwip/sys.h"

#include "lwip/stats.h"

#include "lwip/tcpip.h"

#include "netif/loopif.h"

#include "arch/perf.h"

//#include "httpd.h"
//#include "ftpd.h"
//#include "fs.h"

void ethernetif_init(struct netif *netif);
int init_adapter(int adapter_num);
void shutdown_adapter(void);
void update_adapter(void);

int dbg_printf(const char *fmt, ...)
{
        va_list v;
        int r;

        va_start(v, fmt);
        r = vfprintf(stderr,fmt, v);
        va_end(v);
        return r;
}

static err_t netio_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t 
err)
{
        if (err == ERR_OK && p != NULL)
        {
                tcp_recved(pcb, p->tot_len);
                pbuf_free(p);
        }
        else
                pbuf_free(p);

        if (err == ERR_OK && p == NULL)
        {
                tcp_arg(pcb, NULL);
                tcp_sent(pcb, NULL);
                tcp_recv(pcb, NULL);
                tcp_close(pcb);
        }

        return ERR_OK;
}

static err_t netio_accept(void *arg, struct tcp_pcb *pcb, err_t err)
{
        tcp_arg(pcb, NULL);
        tcp_sent(pcb, NULL);
        tcp_recv(pcb, netio_recv);
        return ERR_OK;
}

void netio_init(void)
{
        struct tcp_pcb *pcb;

        pcb = tcp_new();
        tcp_bind(pcb, IP_ADDR_ANY, 18767);
        pcb = tcp_listen(pcb);
        tcp_accept(pcb, netio_accept);
}

static struct netif netif;



unsigned long ReceiveThread( void ) 
{
        int last_time;
        int timer1;
        int timer2;
        


        last_time=clock();
        timer1=0;
        timer2=0;
        

        while(1)
        {
                int cur_time;
                int time_diff;

                cur_time=clock();
                time_diff=cur_time-last_time;
                //printf("%d %d\n",CLOCKS_PER_SEC,time_diff);
                if (time_diff>0)
                {
                        last_time=cur_time;
                        timer1+=time_diff;
                        timer2+=time_diff;
                }

                if (timer1>200)
                {
                        //printf("Fast timer called\n");
                        tcp_fasttmr();
                        timer1=0;
                }

                if (timer2>450)
                {
                        //printf("Slow timer called\n");
                        tcp_slowtmr();
                        timer2=0;
                
                }
                update_adapter();
        }
}


void main_loop()
{
        struct ip_addr ipaddr, netmask, gw;
        int last_time;
        int timer1;
        int timer2;
        int done;
        
        IP4_ADDR(&gw, 192,168,5,11);
        IP4_ADDR(&ipaddr, 192,168,5,112);
        IP4_ADDR(&netmask, 255,255,255,0);
        
        if (init_adapter(2) != 0)
                return;

        netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, 
ethernetif_init,
                ip_input));
        netif_set_up(&netif);

        /*
        IP4_ADDR(&gw, 127,0,0,1);
        IP4_ADDR(&ipaddr, 127,0,0,1);
        IP4_ADDR(&netmask, 255,0,0,0);
        
        netif_add(&ipaddr, &netmask, &gw, loopif_init,
                ip_input);
        */

        tcp_init();
        udp_init();
        ip_init();

        //httpd_init();
        netio_init();
        //ftpd_init();

        StartThread(ReceiveThread);
        getchar();
        getchar();
        shutdown_adapter();
        return;

}

void bcopy(const void *src, void *dest, int len)
{
  memcpy(dest,src,len);
}

void bzero(void *data, int n)
{
  memset(data,0,n);
}

int main(void)
{
        setvbuf(stdout,NULL,_IONBF,0);
#ifdef PERF
        perf_init("/tmp/lwip.perf");
#endif /* PERF */
#ifdef STATS
        stats_init();
#endif /* STATS */
        sys_init();
        mem_init();
        memp_init();
        pbuf_init();

        //tcpdump_init();

        printf("System initialized.\n");

        main_loop();

        return 0;
}


u16_t 
sys_arch_mbox_fetch(sys_mbox_t mbox, void **data, u16_t timeout)
{

  return 0;
}
_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to