status_t ipv6_setsockopt(net_protocol* _protocol, int level, int option, const void* value, int length) { ipv6_protocol* protocol = (ipv6_protocol*)_protocol; if (level == IPPROTO_IPV6) { // TODO: support more of these options if (option == IPV6_MULTICAST_IF) { if (length != sizeof(struct in6_addr)) return B_BAD_VALUE; struct sockaddr_in6* address = new (std::nothrow) sockaddr_in6; if (address == NULL) return B_NO_MEMORY; if (user_memcpy(&address->sin6_addr, value, sizeof(in6_addr)) != B_OK) { delete address; return B_BAD_ADDRESS; } // Using the unspecifed address to remove the previous setting. if (IN6_IS_ADDR_UNSPECIFIED(&address->sin6_addr)) { delete address; delete protocol->multicast_address; protocol->multicast_address = NULL; return B_OK; } struct net_interface* interface = sDatalinkModule->get_interface_with_address( (sockaddr*)address); if (interface == NULL) { delete address; return EADDRNOTAVAIL; } delete protocol->multicast_address; protocol->multicast_address = (struct sockaddr*)address; sDatalinkModule->put_interface(interface); return B_OK; } if (option == IPV6_MULTICAST_HOPS) { return set_int_option(protocol->multicast_time_to_live, value, length); } if (option == IPV6_MULTICAST_LOOP) return EOPNOTSUPP; if (option == IPV6_UNICAST_HOPS) return set_int_option(protocol->time_to_live, value, length); if (option == IPV6_V6ONLY) return EOPNOTSUPP; if (option == IPV6_RECVPKTINFO) return set_int_option(protocol->receive_pktinfo, value, length); if (option == IPV6_RECVHOPLIMIT) return set_int_option(protocol->receive_hoplimit, value, length); if (option == IPV6_JOIN_GROUP || option == IPV6_LEAVE_GROUP) { ipv6_mreq mreq; if (length != sizeof(ipv6_mreq)) return B_BAD_VALUE; if (user_memcpy(&mreq, value, sizeof(ipv6_mreq)) != B_OK) return B_BAD_ADDRESS; return ipv6_delta_membership(protocol, option, mreq.ipv6mr_interface, &mreq.ipv6mr_multiaddr, NULL); } dprintf("IPv6::setsockopt(): set unknown option: %d\n", option); return ENOPROTOOPT; } return sSocketModule->set_option(protocol->socket, level, option, value, length); }
bool Socket::set_reuse_addr(bool on) { return set_int_option(SO_REUSEADDR, on ? 1 : 0); }
LDAP *ads_init(Env E) { LDAP *ld = NULL; LDAPMessage *result, *e; int i; int h, nh; int rc; char uri[1024]; syslog(LOG_DEBUG, ".. auth_initialize, host=%s\n", E->ads_host); /* Get a handle to the server */ if (E->ads_ca) { /* tls version */ #ifdef LDAP_DEBUG set_ldap_debug(); #endif if (!set_int_option(NULL, LDAP_OPT_PROTOCOL_VERSION, LDAP_VERSION3)) rc=1; if (!set_int_option(NULL, LDAP_OPT_X_TLS, LDAP_OPT_X_TLS_DEMAND)) rc=1; if (!set_char_option(NULL, LDAP_OPT_X_TLS_CACERTFILE, E->ads_ca)) rc=1; sprintf(uri,"ldap://%s:%s/", E->ads_host, E->ads_port); if ( (rc = ldap_initialize(&ld, uri )) != LDAP_SUCCESS ) { report_error(rc, "ldap_initialize"); rc=1; } syslog(LOG_DEBUG, ".. ldap tls initialize ok\n"); } else { /* not tls */ if ( (ld = ldap_init( E->ads_host, atoi(E->ads_port) )) == NULL ) { syslog(LOG_ERR, "non tls ldap_init failed" ); rc=1; } } /* Bind */ if (E->ads_ca && E->ads_crt) { /* cert */ syslog(LOG_DEBUG, "using cert from %s\n", E->ads_crt); if (!set_char_option(NULL, LDAP_OPT_X_TLS_CERTFILE, E->ads_crt)) exit (1); if (!set_char_option(NULL, LDAP_OPT_X_TLS_KEYFILE, E->ads_key)) exit (1); if ((rc=ldap_start_tls_s(ld, NULL, NULL)) != LDAP_SUCCESS) { report_error(rc, "ldap_start_tls_s"); rc=1; } if ((rc=ldap_sasl_interactive_bind_s(ld, NULL, "EXTERNAL", 0, 0, LDAP_SASL_AUTOMATIC|LDAP_SASL_QUIET, tsasl_interact, 0)) != LDAP_SUCCESS) { report_error(rc, "ldap_sasl_interactive_bind_s"); rc=1; } } else { syslog(LOG_ERR, "invalid ldap config\n"); rc=1; } syslog(LOG_DEBUG, ".. ldap bind ok\n"); set_int_option( ld, LDAP_OPT_PROTOCOL_VERSION, LDAP_VERSION3); if (ld) syslog(LOG_DEBUG, ".. ldap connect OK.\n"); else syslog(LOG_DEBUG, ".. ldap connect failed.\n"); E->ldap = ld; // show_cfg(cfg); return (ld); }
bool Socket::set_keep_alive(bool on) { return set_int_option(SO_KEEPALIVE, on ? 1 : 0); }