/**************************************************************************** add an interface to the linked list of interfaces ****************************************************************************/ static void add_interface(struct in_addr ip, struct in_addr nmask) { struct interface *iface; if (iface_find(ip, False)) { DEBUG(3,("not adding duplicate interface %s\n",inet_ntoa(ip))); return; } #if !defined(__s390__) if (ip_equal(nmask, allones_ip)) { DEBUG(3,("not adding non-broadcast interface %s\n",inet_ntoa(ip))); return; } #endif iface = SMB_MALLOC_P(struct interface); if (!iface) return; ZERO_STRUCTPN(iface); iface->ip = ip; iface->nmask = nmask; iface->bcast.s_addr = MKBCADDR(iface->ip.s_addr, iface->nmask.s_addr); DLIST_ADD(local_interfaces, iface); DEBUG(2,("added interface ip=%s ",inet_ntoa(iface->ip))); DEBUG(2,("bcast=%s ",inet_ntoa(iface->bcast))); DEBUG(2,("nmask=%s\n",inet_ntoa(iface->nmask))); }
/**************************************************************************** load the list of network interfaces ****************************************************************************/ void load_interfaces(void) { const char **ptr; int i; struct iface_struct ifaces[MAX_INTERFACES]; ptr = lp_interfaces(); allones_ip = *interpret_addr2("255.255.255.255"); loopback_ip = *interpret_addr2("127.0.0.1"); SAFE_FREE(probed_ifaces); /* dump the current interfaces if any */ while (local_interfaces) { struct interface *iface = local_interfaces; DLIST_REMOVE(local_interfaces, local_interfaces); ZERO_STRUCTPN(iface); SAFE_FREE(iface); } /* probe the kernel for interfaces */ total_probed = get_interfaces(ifaces, MAX_INTERFACES); if (total_probed > 0) { probed_ifaces = memdup(ifaces, sizeof(ifaces[0])*total_probed); } /* if we don't have a interfaces line then use all broadcast capable interfaces except loopback */ if (!ptr || !*ptr || !**ptr) { if (total_probed <= 0) { DEBUG(0,("ERROR: Could not determine network interfaces, you must use a interfaces config line\n")); exit(1); } for (i=0;i<total_probed;i++) { if (probed_ifaces[i].netmask.s_addr != allones_ip.s_addr && probed_ifaces[i].ip.s_addr != loopback_ip.s_addr) { add_interface(probed_ifaces[i].ip, probed_ifaces[i].netmask); } } return; } if (ptr) { while (*ptr) { char *ptr_cpy = strdup(*ptr); if (ptr_cpy) { interpret_interface(ptr_cpy); free(ptr_cpy); } ptr++; } } if (!local_interfaces) { DEBUG(0,("WARNING: no network interfaces found\n")); } }
/**************************************************************************** add an interface to the linked list of interfaces ****************************************************************************/ static void add_interface(TALLOC_CTX *mem_ctx, struct in_addr ip, struct in_addr nmask, struct interface **interfaces) { struct interface *iface; struct in_addr bcast; if (iface_find(*interfaces, ip, false)) { DEBUG(3,("not adding duplicate interface %s\n",inet_ntoa(ip))); return; } iface = talloc(*interfaces == NULL ? mem_ctx : *interfaces, struct interface); if (iface == NULL) return; ZERO_STRUCTPN(iface); iface->ip = ip; iface->nmask = nmask; bcast.s_addr = MKBCADDR(iface->ip.s_addr, iface->nmask.s_addr); /* keep string versions too, to avoid people tripping over the implied static in inet_ntoa() */ iface->ip_s = talloc_strdup(iface, inet_ntoa(iface->ip)); iface->nmask_s = talloc_strdup(iface, inet_ntoa(iface->nmask)); if (nmask.s_addr != ~0) { iface->bcast_s = talloc_strdup(iface, inet_ntoa(bcast)); } DLIST_ADD_END(*interfaces, iface, struct interface *); DEBUG(3,("added interface ip=%s nmask=%s\n", iface->ip_s, iface->nmask_s)); }
void gfree_interfaces(void) { while (local_interfaces) { struct interface *iface = local_interfaces; DLIST_REMOVE(local_interfaces, local_interfaces); ZERO_STRUCTPN(iface); SAFE_FREE(iface); } SAFE_FREE(probed_ifaces); }
static void add_interface(const struct iface_struct *ifs) { char addr[INET6_ADDRSTRLEN]; struct interface *iface; if (iface_find((const struct sockaddr *)&ifs->ip, False)) { DEBUG(3,("add_interface: not adding duplicate interface %s\n", print_sockaddr(addr, sizeof(addr), &ifs->ip) )); return; } if (!(ifs->flags & (IFF_BROADCAST|IFF_LOOPBACK))) { DEBUG(3,("not adding non-broadcast interface %s\n", ifs->name )); return; } iface = SMB_MALLOC_P(struct interface); if (!iface) { return; } ZERO_STRUCTPN(iface); iface->name = SMB_STRDUP(ifs->name); if (!iface->name) { SAFE_FREE(iface); return; } iface->flags = ifs->flags; iface->ip = ifs->ip; iface->netmask = ifs->netmask; iface->bcast = ifs->bcast; DLIST_ADD(local_interfaces, iface); DEBUG(2,("added interface %s ip=%s ", iface->name, print_sockaddr(addr, sizeof(addr), &iface->ip) )); DEBUG(2,("bcast=%s ", print_sockaddr(addr, sizeof(addr), &iface->bcast) )); DEBUG(2,("netmask=%s\n", print_sockaddr(addr, sizeof(addr), &iface->netmask) )); }
void message_register(int msg_type, void (*fn)(int msg_type, pid_t pid, void *buf, size_t len)) { struct dispatch_fns *dfn; dfn = (struct dispatch_fns *)malloc(sizeof(*dfn)); if (dfn != NULL) { ZERO_STRUCTPN(dfn); dfn->msg_type = msg_type; dfn->fn = fn; DLIST_ADD(dispatch_fns, dfn); } else { DEBUG(0,("message_register: Not enough memory. malloc failed!\n")); } }
/**************************************************************************** add an interface to the linked list of interfaces ****************************************************************************/ static void add_interface(TALLOC_CTX *mem_ctx, const struct iface_struct *ifs, struct interface **interfaces, bool enable_ipv6) { char addr[INET6_ADDRSTRLEN]; struct interface *iface; if (iface_list_find(*interfaces, (const struct sockaddr *)&ifs->ip, false)) { DEBUG(3,("add_interface: not adding duplicate interface %s\n", print_sockaddr(addr, sizeof(addr), &ifs->ip) )); return; } if (!(ifs->flags & (IFF_BROADCAST|IFF_LOOPBACK))) { DEBUG(3,("not adding non-broadcast interface %s\n", ifs->name )); return; } if (!enable_ipv6 && ifs->ip.ss_family != AF_INET) { return; } iface = talloc(*interfaces == NULL ? mem_ctx : *interfaces, struct interface); if (iface == NULL) return; ZERO_STRUCTPN(iface); iface->name = talloc_strdup(iface, ifs->name); if (!iface->name) { SAFE_FREE(iface); return; } iface->flags = ifs->flags; iface->ip = ifs->ip; iface->netmask = ifs->netmask; iface->bcast = ifs->bcast; /* keep string versions too, to avoid people tripping over the implied static in inet_ntoa() */ print_sockaddr(addr, sizeof(addr), &iface->ip); DEBUG(4,("added interface %s ip=%s ", iface->name, addr)); iface->ip_s = talloc_strdup(iface, addr); print_sockaddr(addr, sizeof(addr), &iface->bcast); DEBUG(4,("bcast=%s ", addr)); iface->bcast_s = talloc_strdup(iface, addr); print_sockaddr(addr, sizeof(addr), &iface->netmask); DEBUG(4,("netmask=%s\n", addr)); iface->nmask_s = talloc_strdup(iface, addr); /* this needs to be a ADD_END, as some tests (such as the spoolss notify test) depend on the interfaces ordering */ DLIST_ADD_END(*interfaces, iface, NULL); }