/*=========================================================================*/ const char* SLPGetProperty(const char* pcName) /* */ /* Returns the value of the corresponding SLP property name. The returned */ /* string is owned by the library and MUST NOT be freed. */ /* */ /* pcName Null terminated string with the property name, from */ /* Section 2.1 of RFC 2614. */ /* */ /* Returns: If no error, returns a pointer to a character buffer containing*/ /* the property value. If the property was not set, returns the */ /* default value. If an error occurs, returns NULL. The returned */ /* string MUST NOT be freed. */ /*=========================================================================*/ { char conffile[MAX_PATH]; const char* result; memset(conffile,0,MAX_PATH); #ifdef WIN32 ExpandEnvironmentStrings(LIBSLP_CONFFILE,conffile,MAX_PATH); #else strncpy(conffile,LIBSLP_CONFFILE,MAX_PATH-1); #endif if(G_PropertyInit == 0) { if(SLPPropertyReadFile(conffile) == 0) { G_PropertyInit = 1; } else { return 0; } } result = SLPPropertyGet(pcName); return result; }
/*=========================================================================*/ int SLPDPropertyInit(const char* conffile) /*=========================================================================*/ { char* myname = 0; char* myinterfaces = 0; char* myurl = 0; SLPPropertyReadFile(conffile); memset(&G_SlpdProperty,0,sizeof(G_SlpdProperty)); /*-------------------------------------------------------------*/ /* Set the properties without hard defaults */ /*-------------------------------------------------------------*/ G_SlpdProperty.isDA = SLPPropertyAsBoolean(SLPPropertyGet("net.slp.isDA")); G_SlpdProperty.activeDADetection = SLPPropertyAsBoolean(SLPPropertyGet("net.slp.activeDADetection")); if(G_SlpdProperty.activeDADetection) { G_SlpdProperty.DAActiveDiscoveryInterval = atoi(SLPPropertyGet("net.slp.DAActiveDiscoveryInterval")); if(G_SlpdProperty.DAActiveDiscoveryInterval > 1 && G_SlpdProperty.DAActiveDiscoveryInterval < SLPD_CONFIG_DA_FIND ) { G_SlpdProperty.DAActiveDiscoveryInterval = SLPD_CONFIG_DA_FIND; } } else { G_SlpdProperty.DAActiveDiscoveryInterval = 0; } G_SlpdProperty.passiveDADetection = SLPPropertyAsBoolean(SLPPropertyGet("net.slp.passiveDADetection")); G_SlpdProperty.isBroadcastOnly = SLPPropertyAsBoolean(SLPPropertyGet("net.slp.isBroadcastOnly")); G_SlpdProperty.multicastTTL = atoi(SLPPropertyGet("net.slp.multicastTTL")); G_SlpdProperty.multicastMaximumWait = atoi(SLPPropertyGet("net.slp.multicastMaximumWait")); G_SlpdProperty.unicastMaximumWait = atoi(SLPPropertyGet("net.slp.unicastMaximumWait")); G_SlpdProperty.randomWaitBound = atoi(SLPPropertyGet("net.slp.randomWaitBound")); G_SlpdProperty.maxResults = atoi(SLPPropertyGet("net.slp.maxResults")); G_SlpdProperty.traceMsg = SLPPropertyAsBoolean(SLPPropertyGet("net.slp.traceMsg")); G_SlpdProperty.traceReg = SLPPropertyAsBoolean(SLPPropertyGet("net.slp.traceReg")); G_SlpdProperty.traceDrop = SLPPropertyAsBoolean(SLPPropertyGet("net.slp.traceDrop")); G_SlpdProperty.traceDATraffic = SLPPropertyAsBoolean(SLPPropertyGet("net.slp.traceDATraffic")); G_SlpdProperty.DAAddresses = SLPPropertyGet("net.slp.DAAddresses"); G_SlpdProperty.DAAddressesLen = strlen(G_SlpdProperty.DAAddresses); /* TODO make sure that we are using scopes correctly. What about DHCP, etc*/ G_SlpdProperty.useScopes = SLPPropertyGet("net.slp.useScopes"); G_SlpdProperty.useScopesLen = strlen(G_SlpdProperty.useScopes); G_SlpdProperty.locale = SLPPropertyGet("net.slp.locale"); G_SlpdProperty.localeLen = strlen(G_SlpdProperty.locale); G_SlpdProperty.securityEnabled = SLPPropertyAsBoolean(SLPPropertyGet("net.slp.securityEnabled")); G_SlpdProperty.checkSourceAddr = SLPPropertyAsBoolean(SLPPropertyGet("net.slp.checkSourceAddr")); G_SlpdProperty.DAHeartBeat = SLPPropertyAsInteger(SLPPropertyGet("net.slp.DAHeartBeat")); /*-------------------------------------*/ /* Set the net.slp.interfaces property */ /*-------------------------------------*/ if(SLPIfaceGetInfo(SLPPropertyGet("net.slp.interfaces"),&G_SlpdProperty.ifaceInfo) == 0) { if(SLPPropertyGet("net.slp.interfaces")) { if(SLPIfaceSockaddrsToString(G_SlpdProperty.ifaceInfo.iface_addr, G_SlpdProperty.ifaceInfo.iface_count, &myinterfaces) == 0) { if(myinterfaces) { SLPPropertySet("net.slp.interfaces", myinterfaces); xfree(myinterfaces); } } } G_SlpdProperty.interfaces = SLPPropertyGet("net.slp.interfaces"); } G_SlpdProperty.interfacesLen = strlen(G_SlpdProperty.interfaces); /*---------------------------------------------------------*/ /* Set the value used internally as the url for this agent */ /*---------------------------------------------------------*/ /* 27 is the size of "service:directory-agent://(NULL)" */ if(SLPNetGetThisHostname(&myname,1) == 0) { myurl = (char*)xmalloc(27 + strlen(myname)); if(G_SlpdProperty.isDA) { strcpy(myurl,SLP_DA_SERVICE_TYPE); } else { strcpy(myurl,SLP_SA_SERVICE_TYPE); } strcat(myurl,"://"); strcat(myurl,myname); SLPPropertySet("net.slp.agentUrl",myurl); G_SlpdProperty.myUrl = SLPPropertyGet("net.slp.agentUrl"); G_SlpdProperty.myUrlLen = strlen(G_SlpdProperty.myUrl); xfree(myurl); xfree(myname); } /*----------------------------------*/ /* Set other values used internally */ /*----------------------------------*/ G_SlpdProperty.DATimestamp = 1; /* DATimestamp must start at 1 */ G_SlpdProperty.activeDiscoveryXmits = 3; /* ensures xmit on first 3 calls to SLPDKnownDAActiveDiscovery() */ G_SlpdProperty.nextActiveDiscovery = 0; /* ensures xmit on first call to SLPDKnownDAActiveDiscovery() */ G_SlpdProperty.nextPassiveDAAdvert = 0; /* ensures xmit on first call to SLPDKnownDAPassiveDiscovery()*/ return 0; }
/*=========================================================================*/ void SLPDPropertyInit(const char* conffile) /*=========================================================================*/ { struct in_addr ifaddr; struct utsname myname; struct hostent* myhostent; int i; SLPPropertyReadFile(conffile); memset(&G_SlpdProperty,0,sizeof(G_SlpdProperty)); /*-------------------------------------------------------------*/ /* Set the properties with out hard defaults */ /*-------------------------------------------------------------*/ G_SlpdProperty.isBroadcastOnly = SLPPropertyAsBoolean(SLPPropertyGet("net.slp.isBroadcastOnly")); G_SlpdProperty.passiveDADetection = SLPPropertyAsBoolean(SLPPropertyGet("net.slp.passiveDADetection")); G_SlpdProperty.activeDADetection = SLPPropertyAsBoolean(SLPPropertyGet("net.slp.activeDADetection")); G_SlpdProperty.activeDiscoveryAttempts = G_SlpdProperty.activeDADetection * 3; G_SlpdProperty.multicastTTL = atoi(SLPPropertyGet("net.slp.multicastTTL")); G_SlpdProperty.multicastMaximumWait = atoi(SLPPropertyGet("net.slp.multicastMaximumWait")); G_SlpdProperty.unicastMaximumWait = atoi(SLPPropertyGet("net.slp.unicastMaximumWait")); G_SlpdProperty.randomWaitBound = atoi(SLPPropertyGet("net.slp.randomWaitBound")); G_SlpdProperty.traceMsg = SLPPropertyAsBoolean(SLPPropertyGet("net.slp.traceMsg")); G_SlpdProperty.traceReg = SLPPropertyAsBoolean(SLPPropertyGet("net.slp.traceReg")); G_SlpdProperty.traceDrop = SLPPropertyAsBoolean(SLPPropertyGet("net.slp.traceDrop")); G_SlpdProperty.traceDATraffic = SLPPropertyAsBoolean(SLPPropertyGet("net.slp.traceDATraffic")); G_SlpdProperty.DAAddresses = SLPPropertyGet("net.slp.DAAddresses"); G_SlpdProperty.DAAddressesLen = strlen(G_SlpdProperty.DAAddresses); G_SlpdProperty.useScopes = SLPPropertyGet("net.slp.useScopes"); G_SlpdProperty.useScopesLen = strlen(G_SlpdProperty.useScopes); G_SlpdProperty.isDA = SLPPropertyAsBoolean(SLPPropertyGet("net.slp.isDA")); G_SlpdProperty.locale = SLPPropertyGet("net.slp.locale"); G_SlpdProperty.localeLen = strlen(G_SlpdProperty.locale); /*-------------------------------------*/ /* Set the net.slp.interfaces property */ /*-------------------------------------*/ G_SlpdProperty.interfaces = SLPPropertyGet("net.slp.interfaces"); if(*G_SlpdProperty.interfaces == 0) { /* put in all interfaces if none specified */ if(uname(&myname) >= 0) { myhostent = gethostbyname(myname.nodename); if(myhostent != 0) { if(myhostent->h_addrtype == AF_INET) { /* count the interfaces */ for(i=0; myhostent->h_addr_list[i];i++); /* allocate memory 16 bytes per interface*/ G_SlpdProperty.interfaces = (char*)malloc((i * 16) + 1); if(G_SlpdProperty.interfaces == 0) { SLPFatal("slpd is out of memory!\n"); } *(char*)G_SlpdProperty.interfaces = 0; /* null terminate */ for(i=0; myhostent->h_addr_list[i];i++) { memcpy(&ifaddr,myhostent->h_addr_list[i],sizeof(ifaddr)); if(i) { strcat((char*)G_SlpdProperty.interfaces,","); } strcat((char*)G_SlpdProperty.interfaces,inet_ntoa(ifaddr)); } } } } } if(G_SlpdProperty.interfaces) { G_SlpdProperty.interfacesLen = strlen(G_SlpdProperty.interfaces); } /*---------------------------------------------------------*/ /* Set the value used internally as the url for this agent */ /*---------------------------------------------------------*/ G_SlpdProperty.myUrl = (const char*)malloc(25 + strlen(myname.nodename)); if(G_SlpdProperty.myUrl == 0) { SLPFatal("slpd is out of memory!\n"); } if(G_SlpdProperty.isDA) { strcpy((char*)G_SlpdProperty.myUrl,"service:directory-agent://"); } else { strcpy((char*)G_SlpdProperty.myUrl,"service:service-agent://"); } if(uname(&myname) >= 0) { /* 25 is the length of "service:directory-agent://" */ strcat((char*)G_SlpdProperty.myUrl,myname.nodename); } G_SlpdProperty.myUrlLen = strlen(G_SlpdProperty.myUrl); }
int main(int argc, char * argv[]) { char addrString[1024]; int sts; int errorCount = 0; struct sockaddr_storage addr; #ifdef _WIN32 WSADATA wsadata; WSAStartup(MAKEWORD(2, 2), &wsadata); #endif sts = SLPNetResolveHostToAddr("localhost", &addr); if (sts != 0) { printf("error %d with SLPNetResolveHostToAddr.\r\n", sts); errorCount++; } else { printf("addr family = %d\r\n", addr.ss_family); SLPNetSockAddrStorageToString(&addr, addrString, sizeof(addrString)); printf("address = %s\r\n", addrString); } sts = SLPNetResolveHostToAddr("::1", &addr); if (sts != 0) { printf("error %d with SLPNetResolveHostToAddr.\r\n", sts); errorCount++; } else { printf("addr family = %d\r\n", addr.ss_family); SLPNetSockAddrStorageToString(&addr, addrString, sizeof(addrString)); printf("address = %s\r\n", addrString); } sts = SLPPropertyReadFile("e:\\source\\Hogwarts_ActiveX\\OpenSLP\\" "ipv6\\win32\\slpd\\slp.conf"); if (sts == 0) printf("Read config file\r\n"); else printf("No config file found - using defaults.\r\n"); sts = SLPNetIsIPV6(); if (sts == 0) printf("Not using ipv6\r\n"); else printf("Using ipv6\r\n"); sts = SLPNetIsIPV4(); if (sts == 0) printf("Not using ipv4\r\n"); else printf("Using ipv4\r\n"); { struct sockaddr_storage a1; struct sockaddr_storage a2; char testaddr[] = "1:2:3:4:5::6"; struct sockaddr_in * p41 = (struct sockaddr_in *)&a1; struct sockaddr_in6 * p61 = (struct sockaddr_in6 *)&a1; struct sockaddr_in * p42 = (struct sockaddr_in *)&a2; struct sockaddr_in6 * p62 = (struct sockaddr_in6 *)&a2; memset(&a1, 0, sizeof(a1)); memset(&a2, 0, sizeof(a2)); SLPNetSetAddr(&a1, AF_INET6, 2, testaddr, sizeof(testaddr)); memcpy(&a2, &a1, sizeof(a1)); sts = SLPNetCompareAddrs(&a1, &a2); if (sts != 0) printf("Error, address a1 does not equal a2 - copy failed\r\n"); memset(&a2, 0, sizeof(a2)); a2.ss_family = AF_INET6; memcpy(p62->sin6_addr.s6_addr, testaddr, sizeof(testaddr)); p62->sin6_family = AF_INET6; p62->sin6_port = htons(2); sts = SLPNetCompareAddrs(&a1, &a2); if (sts != 0) printf("Error, address a1 does not equal a2\r\n"); } /* now test the ipv6 expansion */ { char t1[] = "::"; char a1[] = "0000:0000:0000:0000:0000:0000:0000:0000"; char t2[] = "1::"; char a2[] = "0001:0000:0000:0000:0000:0000:0000:0000"; char t3[] = "::1"; char a3[] = "0000:0000:0000:0000:0000:0000:0000:0001"; char t4[] = "12::34"; char a4[] = "0012:0000:0000:0000:0000:0000:0000:0034"; char t5[] = "1111:2222:3333::5555:6666:7777:8888"; char a5[] = "1111:2222:3333:0000:5555:6666:7777:8888"; char t6[] = "1:02::003:0004"; char a6[] = "0001:0002:0000:0000:0000:0000:0003:0004"; char t7[] = "0001:0002:0003:0004:0005:0006:0007:0008"; char a7[] = "0001:0002:0003:0004:0005:0006:0007:0008"; char t8[] = "1:02:003:0004:0005:006:07:8"; char a8[] = "0001:0002:0003:0004:0005:0006:0007:0008"; char i1[] = "1::2::3"; char i2[] = "1:::3"; char buf[40]; /* min buf size - 8*4 + 7 + null */ int sts; sts = SLPNetExpandIpv6Addr(t1, buf, sizeof(buf)); if ((sts != 0) || (strcmp(buf, a1) != 0)) printf("Error expanding ipv6 address t1\r\n"); sts = SLPNetExpandIpv6Addr(t2, buf, sizeof(buf)); if ((sts != 0) || (strcmp(buf, a2) != 0)) printf("Error expanding ipv6 address t2\r\n"); sts = SLPNetExpandIpv6Addr(t3, buf, sizeof(buf)); if ((sts != 0) || (strcmp(buf, a3) != 0)) printf("Error expanding ipv6 address t3\r\n"); sts = SLPNetExpandIpv6Addr(t4, buf, sizeof(buf)); if ((sts != 0) || (strcmp(buf, a4) != 0)) printf("Error expanding ipv6 address t4\r\n"); sts = SLPNetExpandIpv6Addr(t5, buf, sizeof(buf)); if ((sts != 0) || (strcmp(buf, a5) != 0)) printf("Error expanding ipv6 address t5\r\n"); sts = SLPNetExpandIpv6Addr(t6, buf, sizeof(buf)); if ((sts != 0) || (strcmp(buf, a6) != 0)) printf("Error expanding ipv6 address t6\r\n"); sts = SLPNetExpandIpv6Addr(t7, buf, sizeof(buf)); if ((sts != 0) || (strcmp(buf, a7) != 0)) printf("Error expanding ipv6 address t7\r\n"); sts = SLPNetExpandIpv6Addr(t8, buf, sizeof(buf)); if ((sts != 0) || (strcmp(buf, a8) != 0)) printf("Error expanding ipv6 address t8\r\n"); sts = SLPNetExpandIpv6Addr(i1, buf, sizeof(buf)); sts = SLPNetExpandIpv6Addr(i2, buf, sizeof(buf)); sts = SLPNetExpandIpv6Addr(t6, buf, 5); if (sts == 0) printf("Error, size not checked for expansion\r\n"); } /* int SLPNetIsMCast(const struct sockaddr_storage *addr); * int SLPNetIsLocal(const struct sockaddr_storage *addr); */ #ifdef _WIN32 WSACleanup(); #endif }