Re: [lwip-users] init network interfaces

2014-07-16 Thread RedCollarPanda
I got it, thank you!



--
View this message in context: 
http://lwip.100.n7.nabble.com/init-network-interfaces-tp22871p22900.html
Sent from the lwip-users mailing list archive at Nabble.com.

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] init network interfaces

2014-07-02 Thread Sergio R. Caprile
* You are confusing lwIP with a Linux/Un*x environment.
** tap/tun is what a port for that environment does, lwIP is just a
TCP/IP stack, not even a library, the library you are using is a compile
of a port for that environment.
*** You have working examples you are supposed to follow, those will
teach you how to initialize interfaces. Beyond that, you should ask for
help in your environment, whether it is Gnu/Linux or BSD or whatever
UN*X flavor you are using.
** You can't bind to an IP address in your machine because lwIP is not
an application or a library for your machine running on top of its
TCP/IP stack; it is an independent TCP/IP stack written for machines
that don't have other TCP/IP stack and so need it. lwIP needs to see a
link-layer interface. The way you are using it is by providing a virtual
interface via a bridge/router. That is a helper to try and debug other
applications. This has been told many times to some other questions of
yours. Do you understand this ?
*** To reach your lwIP-based application you have to connect to the IP
address YOU provide when you setup the stack. Your tun/tap inet addr is
the gateway address YOU provide so the UN*X internal router can reach
your lwIP stack, and they are configured in the file you are using for
the port, either contrib/ports/unix/proj/minimal/main.c or whatever YOU
are using.
 Your lwIP-based application will have that IP address as a source
address, your networking environment must route that network, in other
words, if your destination is in other machine, it must know how to "go
back" to your lwIP stack
* Before debugging @application layer, you should check connectivity.
Start by trying a simple ping



___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] init network interfaces

2014-07-02 Thread RedCollarPanda
Good day!

I want to make  a client and connect it to netcat simple server.

1) Compilled lib with default settings and #define's (the only thing - i set
some debug information on)
2) Linked lib to the project (works fine)
3) Set up virtual machine with ubuntu and made netcat working with 

~$ sudo netcat -l -v 7

  that means we are listening to port 7 (seven).

 now I use ifconfig and get 

inet addr:172.17.9.71 
Bcast:172.17.11.255
Mask:255.255.252.0

fine for now.

4) ping and telnet work fine - I see that netcat is reachable by them .

my ifconfig stats are 

inet addr:172.17.9.165
Bcast:172.17.11.255
Mask:255.255.252.0

5) Now I'm trying to connect to netcat server with my client, written by
using lwip

output is :

LWIP_HAVE_LOOPIF = 0
LWIP_HAVE_LOOPIF = 0
tcp_bind: bind to port 5
tcp_connect to port 7
netif_default =  -780756800
 netif_is_up(netif_default) =  0
 ip_route: No route to 172.17.9.71
connect err =  -4
netif_default =  -780756800
 netif_is_up(netif_default) =  0
 ip_route: No route to 172.17.9.71
ip_output: No route to 172.17.9.71
Assertion "mem_free: mem->used" failed at line 339 in
../../../../../lwip/src/core/mem.c



the full listing :


const char *helloworld = "hello world\n";



void hello_end(struct tcp_pcb *pcb, u8_t *state)
{
 tcp_err(pcb, NULL);
 tcp_recv(pcb, NULL);
 tcp_sent(pcb, NULL);
 tcp_poll(pcb, NULL, 0);
 mem_free(state);
}
err_t hello_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
 u8_t *state = (u8_t *)arg;
 u16_t len;

 if (p == NULL)
 if (*state == 255) /* close send */
 hello_end(pcb, state);
 else /* close not yet send */
 *state |= 2;
 else
 {
 len = p->tot_len;
 pbuf_free(p);
 tcp_recved(pcb, len);
 }

 return ERR_OK;
}

void hello_err(void *arg, err_t err)
{
 mem_free(arg);
}

err_t hello_poll_close(void *arg, struct tcp_pcb *pcb)
{
 u8_t *state = (u8_t *)arg;

 if (tcp_close(pcb) == ERR_OK)
 {
 if ((*state & 2) == 2) /* close received */
 hello_end(pcb, state);
 else /* close not yet received */
 *state = 255;
 }

 return ERR_OK;
}

err_t hello_connected(void *arg, struct tcp_pcb *pcb, err_t err)
{
 tcp_write(pcb, helloworld, 12, 0);
 return ERR_OK;
}

err_t hello_connect() {

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

  IP4_ADDR(&ipaddr, 172,17,9,71);
  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_ANY, 5); //Bind ourselvs to the port 5 
and my
own adress


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

  getchar();
  return ERR_OK;
}

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

 err_t err =  hello_connect();
   if (err != ERR_OK)  {
   std::cout << "2err =  " << err << std::endl;
   }
std::cout << "End of Main" << std::endl;
return 0;


return 0;
}


 
from here I started to think that the problem is that I didnt set up NETIF.

but I don't know HOW.

I think I don't want lwip to create tap0 by default 

(it makes 


tap0  Link encap:Ethernet  HWaddr 86:97:2c:64:b7:78  
  inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
  inet6 addr: fe80::8497:2cff:fe64:b778/64 Scope:Link
  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
  RX packets:0 errors:0 dropped:0 overruns:0 frame:0
  TX packets:33 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:500 
  RX bytes:0 (0.0 B)  TX bytes:6555 (6.4 KiB)
)

I want to bind my application to localhost or to eth1  - whatever... How can
I do this?
What do I do wrong in my application?


By the way - when I do 

  char *eth = "eht1";
  netif_set_default(netif_find(eth));

In my Init function I get this output 

LWIP_HAVE_LOOPIF = 0
LWIP_HAVE_LOOPIF = 0
tcpip_thread: PACKET 0x7f72acaa1988
ip_input: packet not for us.
tcp_bind: bind to port 5
tcp_connect to port 7
netif_default =  0

and it falls on 

 err = tcp_connect(pcb, &ipaddr, 7, hello_connected);

(not passing it...)


Can some 1 help?








--
View this message in context: 
http://lwip.100.n7.nabble.com/init-network-interfaces-tp22871.html
Sent from the lwip-users mailing list archive at Nabble.com.

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users