lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] Help with basic application


From: Noam weissman
Subject: Re: [lwip-users] Help with basic application
Date: Wed, 25 Jun 2014 16:19:29 +0300

Hi,

You should take an example and first run something that works.

First of all you must check your lwipopts.h file. This is per project.

Check if  #define TCP_LISTEN_BACKLOG      is set to 1 or not

Check if  #define NO_SYS is set to     1 or not

Check if   #define MEM_SIZE      ???

Check UDP settings:
/* ---------- UDP options ---------- */
#define LWIP_UDP                1
#define UDP_TTL                 255

Check if CHECKSUM_BY_HARDWARE  is set to 1, if it is you must have a
hardware that supports that

If you work in RAW mode check that   #define LWIP_RAW
1

If you are working with LwIP 1.4x and TCP_LISTEN_BACKLOG       is set to
1 you must call accepted function 
When a new connection is made.

If TCP_LISTEN_BACKLOG   is set to 1  Example:

Define Server_pcb as global in your file or pass it as an arg to the new
server PCB. If you defined it global then:


static struct tcp_pcb *Server_pcb;


------  your init function ----------

void server_init(u16_t  Port)
{
   struct tcp_pcb *pcb;
   err_t err;
  
  
   pcb = tcp_new();
  
  
   if(pcb != NULL)
   {            
     // bind local IP with  port
     err = tcp_bind(pcb, IP_ADDR_ANY, Port);
     
     if(err == ERR_OK)
     {
       // The tcp_listen() function returns a new connection control
block, and 
       // the one passed as an argument to the function will be
deallocated. The 
       // reason for this behavior is that less memory is needed for a
connection 
       // that is listening, so tcp_listen() will reclaim the memory
needed for 
       // the original connection and allocate a new smaller memory
block for the 
       // listening connection.       
       Server_pcb = tcp_listen(pcb);
   
       // if we are here that mean that we did not use all available
connection
       // and we are ready to treat another one.
       tcp_setprio(Server_pcb, TCP_PRIO_MIN);  
       
       
       tcp_accept(Server_pcb, client_accept);
     }
     else
     {
       /* abort? output diagnostic? */    
     }
   }  
   else 
   {
     /* abort? output diagnostic? */  
   }
}


---------------- in your accept function -------------


err_t  client_accept(void *arg, struct tcp_pcb *pcb, err_t err)
{
   tcp_setprio(pcb, TCP_PRIO_NORMAL);
     
  
   // disable nagle algorithm, improve performance with winxp.
   tcp_nagle_disable(pcb); 
   

   // tcp stack, install callback for data received.
   tcp_recv(pcb, client_recv);

   // tcp stack, install callback for connection errors such as timeout
and TCP RST
   tcp_err(pcb, conn_err);


   // this function call does nothing. Usefull only if
TCP_LISTEN_BACKLOG is set.
   // If TCP_LISTEN_BACKLOG is set to 1 and tcp_accepted function is not
called 
   // it will cause the server to stop working. So this function call is
a must.
   tcp_accepted(Server_pcb);
   
   
   return ERR_OK;
}


------------------------------------------------------------------------
----------------


Hope that helped...


BR,
Noam.







-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of
RedCollarPanda
Sent: Wednesday, June 25, 2014 11:17 AM
To: address@hidden
Subject: [lwip-users] Help with basic application

Listen, ppl, I know you are tired of such questions and so on, but I
really need help. The thing is - i need a resver and a client made with
lwip library with raw interfaces. So far I didn't do much... 

I REALLY need your help. Can you tell me - what am I doing wrong? I'll
tell what I'm doing.
First of all I compile the library. I didn't change the lwipopts.h - all
by default.

1) As I understood i need to call some init() method (func) and go to
the
while(true) { } endless cycle.
As I did - 

int main(int argc, char** argv) {


        echo_init();
        std::cout << "endles cycle" << std::endl;
        while(1) {

        }
        return 0;
} 



2) In the echo_init(); function I must

a) echo_pcb = tcp_new();  // - create ne pcb

b)  err_t err;
    ip_addr_t ipaddr;   //create variables for error checking and IP
address
I wanna use with my server.

c)  IP4_ADDR(&ipaddr, 150,18,8,165);  //Put in variable adress of MY
machine 

      /*      ifconfig says  
           eth1      Link encap:Ethernet    
          inet addr:150.18.8.165  Bcast:150.18.11.255*
Mask:255.255.251.0 */

    err = tcp_bind(echo_pcb, &ipaddr, 667); //than bind IP address and
desired port to the pcb

d)   echo_pcb = tcp_listen(echo_pcb);   //Than I listen pcb
      tcp_accept(echo_pcb, echo_accept); //If there is request  - accept
in

//End of init.

Is this logic correct?


The client.
I want to connect to ANY TCP server and transmit the package.

What I do :

1)
int main(int argc, char** argv) {
         err_t err =    hello_connect();
         if (err != ERR_OK)  {
                 std::cout << "err =  " << err << std::endl;    
          }
        std::cout << "End of Main" << std::endl;
        return 0;
}

2) In hello_connect();

        lwip_init();
        u8_t *state;
        err_t err;
        struct tcp_pcb *pcb;
         ip_addr_t ipaddr;

      IP4_ADDR(&ipaddr, 150,18,8,165);
      if ((state = mem_malloc(1)) == NULL)  {
         return ERR_MEM;
      }

       *state = 1;
       if ((pcb = tcp_new()) == NULL)  {
       mem_free(state);
       return ERR_MEM;
      }

      tcp_arg(pcb, state);
      tcp_err(pcb, hello_err);
      tcp_recv(pcb, hello_recv);
      tcp_sent(pcb, NULL);
      tcp_poll(pcb, hello_poll_close, 10);

      tcp_bind(pcb,&ipaddr, 55555); //Bind ourselvs to the port 55555
and my own adress again

      err = tcp_connect(pcb, &ipaddr, 667, hello_connected);
      if (err != ERR_OK)  {
         std::cout << "err =  " << err << std::endl; 
        mem_free(state);
         tcp_abort(pcb);
}


Troubles:

1) Server begins it's work but creates tap0. Why?

tap0      Link encap:Ethernet  HWaddr ************
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a82b:dcff:fedf:3964/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:40 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:500 
          RX bytes:0 (0.0 B)  TX bytes:8136 (7.9 KiB)

Wanna scan and find my server with 667 port :

sudo nmap -sT -O 192.168.1.1


Starting Nmap 6.00 ( http://nmap.org ) at 2014-06-25 11:58 MSK Nmap scan
report for 192.168.1.1 Host is up (0.000011s latency).
Not shown: 996 closed ports
PORT    STATE SERVICE
22/tcp  open  ssh
111/tcp open  rpcbind
443/tcp open  https
902/tcp open  iss-realsecure
No exact OS matches for host (If you know what OS is running on it, see
http://nmap.org/submit/ ).
TCP/IP fingerprint:
OS:SCAN(V=6.00%E=4%D=6/25%OT=22%CT=1%CU=40454%PV=Y%DS=0%DC=L%G=Y%TM=53AA
812
OS:3%P=x86_64-unknown-linux-gnu)SEQ(SP=108%GCD=1%ISR=10A%TI=Z%CI=I%II=I%
TS=
OS:8)OPS(O1=M400CST11NW7%O2=M400CST11NW7%O3=M400CNNT11NW7%O4=M400CST11NW
7%O
OS:5=M400CST11NW7%O6=M400CST11)WIN(W1=8000%W2=8000%W3=8000%W4=8000%W5=80
00%
OS:W6=8000)ECN(R=Y%DF=Y%T=41%W=8018%O=M400CNNSNW7%CC=Y%Q=)T1(R=Y%DF=Y%T=
41%
OS:S=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=41%W=0%S=A%A=Z%F=R%
O=%
OS:RD=0%Q=)T5(R=Y%DF=Y%T=41%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=4
1%W
OS:=0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=41%W=0%S=Z%A=S+%F=AR%O=%RD=0%
Q=)
OS:U1(R=Y%DF=N%T=41%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=
Y%D
OS:FI=N%T=41%CD=S)

Network Distance: 0 hops

OS detection performed. Please report any incorrect results at
http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 25.97 seconds

So where is my server???

when I execute client 

  "tcp_connect to port 667"
And that is it....




By the way if I'm making client like this :

        u8_t *state;
        err_t err;
        struct tcp_pcb *pcb;
      ip_addr_t ipaddr;
      netif_init();
      IP4_ADDR(&ipaddr, 127,0,0,1); 
     if ((state = mem_malloc(1)) == NULL) {
         return ERR_MEM;
     }

      *state = 1;
      if ((pcb = tcp_new()) == NULL)  {
      mem_free(state);
      return ERR_MEM;
      }
      tcp_arg(pcb, state);
      tcp_err(pcb, hello_err);
      tcp_recv(pcb, hello_recv);
      tcp_sent(pcb, NULL);
      tcp_poll(pcb, hello_poll_close, 10);
 
 
      err = tcp_connect(pcb, &ipaddr, 667, hello_connected);
     if (err != ERR_OK)  {
         std::cout << "err =  " << err << std::endl;
         std::cout << "err =  " << (int)err << std::endl;
         mem_free(state);
         tcp_abort(pcb);
 }


then I have this in my console

LWIP_HAVE_LOOPIF = 1
 
tcp_connect to port 667
ip_output_if: lo2
IP header:
+-------------------------------+
| 4 | 5 |  0x00 |        44     | (v, hl, tos, len)
+-------------------------------+
|        0      |000|       0   | (id, flags, offset)
+-------------------------------+
|  255  |    6  |    0xbdc9     | (ttl, proto, chksum)
+-------------------------------+
|  127  |    0  |    0  |    1  | (src)
+-------------------------------+
|  127  |    0  |    0  |    1  | (dest)
+-------------------------------+
netif_loop_output()
tcpip_thread: CALLBACK 0x7f1fbe811868
ip_input: packet accepted on interface lo
ip_input: 
IP header:
+-------------------------------+
| 4 | 5 |  0x00 |        44     | (v, hl, tos, len)
+-------------------------------+
|        0      |000|       0   | (id, flags, offset)
+-------------------------------+
|  255  |    6  |    0xbdc9     | (ttl, proto, chksum)
+-------------------------------+
|  127  |    0  |    0  |    1  | (src)
+-------------------------------+
|  127  |    0  |    0  |    1  | (dest)
+-------------------------------+
ip_input: p->len 44 p->tot_len 44
ip_output_if: lo2
IP header:
+-------------------------------+
| 4 | 5 |  0x00 |        40     | (v, hl, tos, len)
+-------------------------------+
|        1      |000|       0   | (id, flags, offset)
+-------------------------------+
|  255  |    6  |    0xbdcc     | (ttl, proto, chksum)
+-------------------------------+
|  127  |    0  |    0  |    1  | (src)
+-------------------------------+
|  127  |    0  |    0  |    1  | (dest)
+-------------------------------+
netif_loop_output()ip_input: packet accepted on interface lo
ip_input: 
IP header:
+-------------------------------+
| 4 | 5 |  0x00 |        40     | (v, hl, tos, len)
+-------------------------------+
|        1      |000|       0   | (id, flags, offset)
+-------------------------------+
|  255  |    6  |    0xbdcc     | (ttl, proto, chksum)
+-------------------------------+
|  127  |    0  |    0  |    1  | (src)
+-------------------------------+
|  127  |    0  |    0  |    1  | (dest)
+-------------------------------+
ip_input: p->len 40 p->tot_len 40

 hello_err BEGINE  //This is the mark of error handler
 hello_err END        //This is the mark of error handler

tcp_pcb_purge
tcp_pcb_purge: data left on ->unacked
tcpip_thread: CALLBACK 0x7f1fbe811840
tcpip_thread: PACKET 0x7f1fbe8119a8


WHRERE are the packets going?? Who recieves them?

Summary:
I need to make them both working - 

Server to w8 for the data, get it and show it.
Client send data to the server.

I wanna use IP on my machine, just change the port number. 


What's wrong here?




--
View this message in context:
http://lwip.100.n7.nabble.com/Help-with-basic-application-tp22827.html
Sent from the lwip-users mailing list archive at Nabble.com.

_______________________________________________
lwip-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users

 
 
************************************************************************
************
This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals &
computer viruses.
************************************************************************
************






************************************************************************************
This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals & computer 
viruses.
************************************************************************************






reply via email to

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