int initialize_rip (rip_table_t * pointer, int port){ int flag = udp_open (port); if (flag == -1) { print_alert ("Unable to open port\n"); printf("\tripv2.c: initialize_rip(): udp_open = -1\n"); } else join_multicast( RIP_MULTICAST_IPv4 ); pointer->num_entries = 0; return flag; }
static void nl_newaddress(time_t now) { if (option_bool(OPT_CLEVERBIND) || daemon->doing_dhcp6 || daemon->doing_ra) enumerate_interfaces(); if (option_bool(OPT_CLEVERBIND)) create_bound_listeners(0); #ifdef HAVE_DHCP6 if (daemon->doing_dhcp6 || daemon->doing_ra) { join_multicast(0); dhcp_construct_contexts(now); } if (daemon->doing_dhcp6) lease_find_interfaces(now); #endif }
static int distribution_probe(void) { if (c_ip) { int err; char s[INET6_ADDRSTRLEN]; struct addrinfo hints = { .ai_socktype = SOCK_DGRAM, .ai_family = c_ipv6 ? PF_INET6 : PF_INET, }; struct addrinfo *res = NULL, *t; if (c_ipv6 && !strcmp(c_ip, "224.0.0.1")) c_ip = "ff01::1"; if ((err = getaddrinfo(c_ip, c_port, &hints, &res)) < 0) quit("getaddrinfo failed: %s\n", gai_strerror(err)); for (t = res; t; t = t->ai_next) { if (c_debug) { const char *x = xinet_ntop(t->ai_addr, s, sizeof(s)); fprintf(stderr, "Trying %s...", x ? x : "null"); } recv_fd = socket(t->ai_family, t->ai_socktype, 0); if (recv_fd < 0) { if (c_debug) fprintf(stderr, "socket() failed: %s\n", strerror(errno)); continue; } if (c_multicast) { if (join_multicast(recv_fd, t->ai_addr, c_iface) < 0) continue; if (!c_bind) goto skip_bind; } if (bind(recv_fd, t->ai_addr, t->ai_addrlen) < 0) { if (c_debug) fprintf(stderr, "bind() failed: %s\n", strerror(errno)); continue; } skip_bind: if (c_debug) fprintf(stderr, "OK\n"); goto ok; } fprintf(stderr, "Could not create and connect a datagram " \ "socket, tried:\n"); for (t = res; t; t = t->ai_next) { const char *x = xinet_ntop(t->ai_addr, s, sizeof(s)); fprintf(stderr, "\t%s\n", x ? x : "null"); } quit("Last error message was: %s\n", strerror(errno)); } else { if (c_ipv6) { struct sockaddr_in6 addr = { .sin6_family = AF_INET6, .sin6_addr = IN6ADDR_ANY_INIT, .sin6_port = htons(c_port_int), }; recv_fd = socket(AF_INET6, SOCK_DGRAM, 0); if (recv_fd < 0) goto try_4; if (bind(recv_fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) goto try_4; goto ok; } try_4: recv_fd = socket(AF_INET, SOCK_DGRAM, 0); if (recv_fd < 0) quit("socket creation failed: %s\n", strerror(errno)); { struct sockaddr_in addr = { .sin_family = AF_INET, .sin_port = htons(c_port_int), }; /* * Guess what, NetBSD is f****d up so this can't be in the * initializer */ addr.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(recv_fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) quit("bind failed: %s\n", strerror(errno)); } goto ok; } ok: { int flags; if ((flags = fcntl(recv_fd, F_GETFL)) < 0) quit("fcntl failed: %s\n", strerror(errno)); if (fcntl(recv_fd, F_SETFL, flags | O_NONBLOCK) < 0) quit("fcntl failed: %s\n", strerror(errno)); } return 1; }