[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-users] Sharing TCP port
From: |
Danish Ali |
Subject: |
[lwip-users] Sharing TCP port |
Date: |
Mon, 15 Mar 2021 15:15:37 +0000 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 |
I would like to be able to have multiple simultaneous TCP links to a
single port (in my case 5060 for SIP).
I have in lwipopts.h
#define SO_REUSE 1
I can receive incoming links fairly easily by way of:
err_t tcp_err = ERR_CLSD;
siptcp_accept = netconn_new_with_callback(NETCONN_TCP, sipconn_callback);
if (siptcp_accept != nullptr) {
ip_set_option(siptcp_accept->pcb.tcp, SOF_REUSEADDR);
tcp_err = netconn_bind(siptcp_accept, IP_ADDR_ANY, 5060);
}
if (tcp_err == ERR_OK) {
logString("Listening for SIP TCP on port 5060\n");
netconn_listen(siptcp_accept);
And then in my event loop
if (siptcp_accept->acceptmbox->n > 0) {
netconn *accept = nullptr;
err_t accept_err = netconn_accept(siptcp_accept, &accept);
if (accept_err == ERR_OK) {
But I am not sure how to make _outgoing_ TCP links such that they will
share that same port number.
I start with
netconn *create = netconn_new(NETCONN_TCP);
how do I tell lwip that I want it to be on 5060 on my local port before
I tell it the remote address I want to connect to?
If I try
err_t tcp_err = netconn_bind(create, &remote.IPAddress, 5060);
I get the error ERR_USE = -8 /** Address in use. */
And if I skip that and immediately call
tcp_err = netconn_connect(create, &remote.IPAddress, remote.port);
it opens with a random port. I want it to come from 5060 on my machine
because other ports might be blocked by a firewall.
Is this possible in lwip? If so, how might I do it?
Many thanks,
Danish
- [lwip-users] Sharing TCP port,
Danish Ali <=