lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] Help with basic application


From: RedCollarPanda
Subject: [lwip-users] Help with basic application
Date: Wed, 25 Jun 2014 01:16:30 -0700 (PDT)

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=53AA812
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=M400CST11NW7%O
OS:5=M400CST11NW7%O6=M400CST11)WIN(W1=8000%W2=8000%W3=8000%W4=8000%W5=8000%
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=41%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.



reply via email to

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