Note that there are some explanatory texts on larger screens.

plurals
  1. PONot able to receive UDP/IPv6 packets on secondary interface
    primarykey
    data
    text
    <p>I have the following C code for UDP server which would bind to the ipv6 address of the secondary interface tap0.</p> <pre><code>context_t * new_context(const struct sockaddr *listen_addr, size_t addr_size) { context_t *c = malloc( sizeof( context_t ) ); time_t now; int reuse = 1; if (!listen_addr) { fprintf(stderr, "no listen address specified\n"); return NULL; } srand( getpid() ^ time(&amp;now) ); if ( !c ) { perror("init: malloc:"); return NULL; } memset(c, 0, sizeof( context_t ) ); c-&gt;sockfd = socket(listen_addr-&gt;sa_family, SOCK_DGRAM, 0); if ( c-&gt;sockfd &lt; 0 ) { perror("new_context: socket"); goto onerror; } if ( setsockopt( c-&gt;sockfd, SOL_SOCKET, SO_REUSEADDR, &amp;reuse, sizeof(reuse) ) &lt; 0 ) perror("setsockopt SO_REUSEADDR"); if ( bind (c-&gt;sockfd, listen_addr, addr_size) &lt; 0 ) { perror("new_context: bind"); goto onerror; } return c; onerror: if ( c-&gt;sockfd &gt;= 0 ) close ( c-&gt;sockfd ); free( c ); return NULL; } context_t * get_context(const char *ipaddress, const char *port, unsigned int scopeId) { int s; context_t* ctx; struct addrinfo hints; struct addrinfo *result, *rp; memset(&amp;hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ hints.ai_socktype = SOCK_DGRAM; /* Coap uses UDP */ hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST | AI_NUMERICSERV | AI_ALL; s = getaddrinfo(ipaddress, port, &amp;hints, &amp;result); if ( s != 0 ) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s)); return NULL; } /* iterate through results until success */ for (rp = result; rp != NULL; rp = rp-&gt;ai_next) { ctx = new_context(rp-&gt;ai_addr, rp-&gt;ai_addrlen); if (ctx) { if ( rp-&gt;ai_family == PF_INET6 ) { struct sockaddr_in6* pSadrIn6 = (struct sockaddr_in6*) rp-&gt;ai_addr; if ( pSadrIn6-&gt;sin6_scope_id == 0 ) { pSadrIn6-&gt;sin6_scope_id = scopeId; } /* End IF the scope ID wasn't set. */ } goto finish; } } fprintf(stderr, "no context available for interface '%s'\n", node); finish: freeaddrinfo(result); return ctx; } </code></pre> <p>Device tap0 has following details:</p> <pre><code>tap0 Link encap:Ethernet HWaddr ce:23:fc:81:7f:65 inet6 addr: fe80::cc23:fcff:fe81:7f65/64 Scope:Link inet6 addr: aaaa::1/64 Scope:Global </code></pre> <p>I run the above code with the following command:</p> <pre><code>./server -A aaaa::1 </code></pre> <p>But it's not able to listen to the messages coming to the address aaaa::1 on tap0. I can see the packets on the wireshark dump on tap0 interface. Interestingly, the server ran from the above command(and code) can receive the messages through the localhost. So, if I execute the following command, the server receives the messages:</p> <pre><code>nc -6 -vvv -u aaaa::1 61616 &lt; /tmp/send_to_node_raw </code></pre> <p>The above command sending and reception is done through localhost. Is there any way I can programatically receive UDP/IPv6 messages on secondary interfaces?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload