Macos 浏览域中的LDAP服务器
我跟在后面 我使用以下代码显示域中的LDAP服务器:Macos 浏览域中的LDAP服务器,macos,dns,ldap,Macos,Dns,Ldap,我跟在后面 我使用以下代码显示域中的LDAP服务器: #include <dns_sd.h> #include <stdio.h> #include <pthread.h> void ResolveCallBack(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
#include <dns_sd.h>
#include <stdio.h>
#include <pthread.h>
void ResolveCallBack(DNSServiceRef sdRef,
DNSServiceFlags flags,
uint32_t interfaceIndex,
DNSServiceErrorType errorCode,
const char *fullname,
const char *hosttarget,
uint16_t port, /* In network byte order */
uint16_t txtLen,
const unsigned char *txtRecord,
void *context) {
}
void BrowserCallBack(DNSServiceRef inServiceRef,
DNSServiceFlags inFlags,
uint32_t inIFI,
DNSServiceErrorType inError,
const char* inName,
const char* inType,
const char* inDomain,
void* inContext) {
DNSServiceErrorType err = DNSServiceResolve(&inServiceRef,
0, // Indicate it's a shared connection.
inIFI,
inName,
inType,
inDomain,
ResolveCallBack,
NULL);
printf("DNSServiceResolve err = %x, name = %s, type=%s, domain=%s\n",
err, inName, inType, inDomain);
}
int main() {
DNSServiceRef ServiceRef;
DNSServiceErrorType err = DNSServiceBrowse(&ServiceRef, // Receives reference to Bonjour browser object.
kDNSServiceFlagsDefault, // Indicate it's a shared connection.
kDNSServiceInterfaceIndexAny, // Browse on all network interfaces.
"_ldap._tcp", // Browse for service types.
NULL, // Browse on the default domain (e.g. local.).
BrowserCallBack, // Callback function when Bonjour events occur.
NULL); // Callback context.
printf("err = 0x%x\n", err);
int sockfd = DNSServiceRefSockFD(ServiceRef);
printf("sockfd = %d\n", sockfd);
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
struct timeval timeout;
timeout.tv_sec = 1;
timeout.tv_usec = 0;
fd_set descriptors;
FD_ZERO(&descriptors);
FD_SET(sockfd, &descriptors);
int r = select(sockfd + 1, &descriptors, NULL, NULL, &timeout);
printf("r = %d\n", r);
fflush(stdout);
if (r > 0) {
if (FD_ISSET(sockfd, &descriptors)) {
// This function will call the appropiate callback to process the
// event, in this case the BrowseReply static method.
err = DNSServiceProcessResult(ServiceRef);
if (err != kDNSServiceErr_NoError) {
printf("Error on process an event in event loop, e = 0x%x\n", err);
}
}
} else if (r == -1) {
printf("The select() call failed");
}
return 0;
}
#包括
#包括
#包括
无效解析回调(DNSServiceRef sdRef,
DNSServiceFlags标志,
uint32_t接口索引,
DNSServiceErrorType错误代码,
常量字符*全名,
const char*hosttarget,
uint16\u t端口,/*以网络字节顺序排列*/
uint16_t txtLen,
常量无符号字符*txtRecord,
void*上下文){
}
无效浏览器回调(DNSServiceRef inServiceRef,
DNSSERVICES,
uint32_t inIFI,
DNSServiceErrorType错误,
const char*inName,
常量字符*inType,
常量char*inDomain,
无效*文本){
DNSServiceErrorType err=DNSServiceResolve(&inServiceRef),
0,//表示它是共享连接。
伊尼菲,
名下,
输入,
印度支那,
解决回调问题,
无效);
printf(“DNSServiceResolve错误=%x,名称=%s,类型=%s,域=%s\n”,
err、inName、inType、inDomain);
}
int main(){
DNSServiceRef服务参考;
DNSServiceErrorType err=DNSServiceBrowse(&ServiceRef,//接收对Bonjour浏览器对象的引用。
kDNSServiceFlagsDefault,//表示它是共享连接。
kDNSServiceInterfaceIndexAny,//浏览所有网络接口。
“\u ldap.\u tcp”,//浏览服务类型。
NULL,//在默认域(例如本地)上浏览。
BrowserCallBack,//发生Bonjour事件时的回调函数。
NULL);//回调上下文。
printf(“err=0x%x\n”,err);
int-sockfd=DNSServiceRefSockFD(ServiceRef);
printf(“sockfd=%d\n”,sockfd);
pthread_setcancelstate(pthread_CANCEL_ENABLE,0);
pthread_setcanceltype(pthread_CANCEL_异步,0);
结构timeval超时;
timeout.tv_sec=1;
timeout.tv_usec=0;
fd_集描述符;
FD_零(和描述符);
FD_集(sockfd和描述符);
int r=select(sockfd+1和描述符、NULL、NULL和超时);
printf(“r=%d\n”,r);
fflush(stdout);
如果(r>0){
if(FD_ISSET(sockfd和描述符)){
//此函数将调用appropiate回调来处理
//事件,在本例中为BrowseReply静态方法。
err=DNSServiceProcessResult(ServiceRef);
if(err!=kDNSServiceErr\u NoError){
printf(“在事件循环中处理事件时出错,e=0x%x\n”,err);
}
}
}else if(r==-1){
printf(“select()调用失败”);
}
返回0;
}
然而,这并没有给我任何LDAP服务器。
有什么帮助吗
提前谢谢
注:
- 此命令返回结果: $nslookup-type=any\u ldap.\u tcp 因此,域中存在LDAP服务器
- 当我尝试将“\u http.\u tcp”作为注册类型时,返回 结果
- 操作系统是MacOSX10.9