示例#1
0
void HowlSession::PublishPort(sw_discovery session, SCRendezvousProtocol protocol, short portNum)
{
	const char* serviceType = SCRendezvousProtocolString(protocol);
	sw_discovery_oid oid;

	sw_result res =
		sw_discovery_publish(
			session,
			0,							// interface
			kSCRendezvousServiceName,	// name
			serviceType,				// type
			0,							// domain (.local)
			0,							// host
			portNum,					// port
			0, 0,						// text records
			howl_publish_reply_func, 0,	// reply func
			&oid						// request id
			);

	scprintf(
		"Zeroconf: publishing service %s on port %hu %s\n",
		serviceType, portNum,
		res == SW_OKAY ? "succeeded" : "failed"
		);
}
示例#2
0
/*
 * rend_callback
 *
 * This gets called from the main thread when there is a 
 * message waiting to be processed.
 */
void rend_callback(void) {
    REND_MESSAGE msg;
    sw_discovery_oid rend_oid;
    sw_result result;

    /* here, we've seen the message, now we have to process it */

    if(rend_read_message(&msg) != sizeof(msg)) {
	DPRINTF(E_FATAL,L_REND,"Rendezvous socket closed (daap server crashed?)  Aborting.\n");
	exit(EXIT_FAILURE);
    }

    switch(msg.cmd) {
    case REND_MSG_TYPE_REGISTER:
	DPRINTF(E_DBG,L_REND,"Registering %s.%s (%d)\n",msg.type,msg.name,msg.port);
	if((result=sw_discovery_publish(rend_handle,
					0, /* interface handle */
					msg.name,
					msg.type,
					NULL, /* domain */
					NULL, /* host */
					msg.port,
					"\011txtvers=1\034Database ID=beddab1edeadbea7", /* text record */
					39, /* text record length */
					rend_howl_reply,
					NULL,
					&rend_oid)) != SW_OKAY) {
	    DPRINTF(E_WARN,L_REND,"Error registering name\n");
	    rend_send_response(-1);
	} else {
	    rend_send_response(0); /* success */
	}
	break;
    case REND_MSG_TYPE_UNREGISTER:
	DPRINTF(E_WARN,L_REND,"Unsupported function: UNREGISTER\n");
	rend_send_response(-1); /* error */
	break;
    case REND_MSG_TYPE_STOP:
	DPRINTF(E_DBG,L_REND,"Stopping mDNS\n");
	rend_send_response(0);
	//sw_rendezvous_stop_publish(rend_handle);
	sw_discovery_fina(rend_handle);
	break;
    case REND_MSG_TYPE_STATUS:
	DPRINTF(E_DBG,L_REND,"Status inquiry -- returning 0\n");
	rend_send_response(0); /* success */
	break;
    default:
	break;
    }
}