- if(origpriority == -1 && n->prevedge) {
- sock = rand() % listen_sockets;
- memset(&broadcast, 0, sizeof broadcast);
- if(listen_socket[sock].sa.sa.sa_family == AF_INET6) {
- broadcast.in6.sin6_family = AF_INET6;
- broadcast.in6.sin6_addr.s6_addr[0x0] = 0xff;
- broadcast.in6.sin6_addr.s6_addr[0x1] = 0x02;
- broadcast.in6.sin6_addr.s6_addr[0xf] = 0x01;
- broadcast.in6.sin6_port = n->prevedge->address.in.sin_port;
- broadcast.in6.sin6_scope_id = listen_socket[sock].sa.in6.sin6_scope_id;
- } else {
- broadcast.in.sin_family = AF_INET;
- broadcast.in.sin_addr.s_addr = -1;
- broadcast.in.sin_port = n->prevedge->address.in.sin_port;
- }
- sa = &broadcast;
- } else {
- if(origpriority == -1)
- origpriority = 0;
-
- if(n->status.udp_confirmed) {
- /* Address of this node is confirmed, so use it. */
- sa = &n->address;
- sock = n->sock;
- } else {
- /* Otherwise, go through the list of known addresses of
- this node. The first address we try is always the
- one in n->address; that could be set to the node's
- reflexive UDP address discovered during key
- exchange. The other known addresses are those found
- in edges to this node. */
-
- static unsigned int i;
- int j = 0;
- edge_t *candidate = NULL;
-
- if(i) {
- for splay_each(edge_t, e, edge_weight_tree) {
- if(e->to != n)
- continue;
- j++;
- if(!candidate || j == i)
- candidate = e;
- }
- }
-
- if(!candidate) {
- sa = &n->address;
- sock = n->sock;
- } else {
- sa = &candidate->address;
- sock = rand() % listen_sockets;
- }
-
- if(i++)
- if(i > j)
- i = 0;
- }
- }
-
- /* Determine which socket we have to use */
-
- if(sa->sa.sa_family != listen_socket[sock].sa.sa.sa_family)
- for(sock = 0; sock < listen_sockets; sock++)
- if(sa->sa.sa_family == listen_socket[sock].sa.sa.sa_family)
- break;
-
- if(sock >= listen_sockets)
- sock = 0;
-
- if(!n->status.udp_confirmed)
- n->sock = sock;