buglwIP - A Lightweight TCP/IP stack - Bugs: bug #55604, UDP can bind to same port when use...


You are not allowed to post comments on this tracker with your current authentication level.

bug #55604: UDP can bind to same port when use IPv4 ANY and IPv6 ANY ,SO_REUSEADDR is disable and IPV6_V6ONLY is disable

Submitter:  vinu <vineeshvinu>
Submitted:  Tue 29 Jan 2019 04:24:14 PM UTC
Category:  UDP Severity:  3 - Normal
Item Group:  Faulty Behaviour Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open Planned Release:  None
lwIP version:  2.1.1

Tue 29 Jan 2019 04:24:14 PM UTC, original submission:  

Below bind will be success since the check inside udp_bind will not match IPv4 any and IPv6 Any type, please check once
IP_GET_TYPE(&ipcb->local_ip) will be 0 and IP_GET_TYPE(ipaddr) is 46
if ((ipcb->local_port == port) &&
              (IP_GET_TYPE(&ipcb->local_ip) == IP_GET_TYPE(ipaddr)) &&
              /* IP address matches or any IP used? */
              (ip_addr_cmp(&ipcb->local_ip, ipaddr) ||
              ip_addr_isany(ipaddr) ||
              ip_addr_isany(&ipcb->local_ip))) {
            /* other PCB already binds to this local IP and port */
                        ("udp_bind: local port %"U16_F" already bound by another pcb\n", port));
            return ERR_USE;

SO_REUSEADDR = disable
IPV6_V6ONLY  = disable
void test2_cmd(unsigned int p0, unsigned int p1, unsigned int p2, unsigned int p3)
int sock4, sock6;
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
int ret;

sock4 = socket(AF_INET, SOCK_DGRAM, 0);
sock6 = socket(AF_INET6, SOCK_DGRAM, 0);

sin.sin_family = AF_INET;
sin.sin_port = htons(4444);
inet_pton(AF_INET, "", &sin.sin_addr);

sin6.sin6_family = AF_INET6;
sin6.sin6_port = htons(4444);
sin6.sin6_flowinfo = 0;
inet_pton(AF_INET6, "::", &sin6.sin6_addr);

int reuse = 0;
ret = setsockopt(sock4, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
if (ret < 0) {

ret = setsockopt(sock6, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
if (ret < 0) {

int v6only = 0;
ret = setsockopt(sock6, IPPROTO_IPV6, IPV6_V6ONLY, &v6only, sizeof(v6only));
if (ret < 0) {

ret = bind(sock4, (struct sockaddr*)&sin, sizeof(sin));
if (ret < 0) {

ret = bind(sock6, (struct sockaddr*)&sin6, sizeof(sin6));
if (ret < 0) {

vinu <vineeshvinu>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by vineeshvinu (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.


    No changes have been made to this item

    Back to the top

    Powered by Savane 3.13-6ae7.
    Corresponding source code