From fa48f1175b108c237cfbbbec481aaa4deceedcc5 Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Mon, 15 Aug 2005 03:16:54 +0000 Subject: [PATCH] specify interface to register --- src/rend-posix.c | 29 ++++++++++++++++++++++++++--- src/rend-unix.c | 9 ++++++--- src/rend-unix.h | 4 ++++ src/rend.h | 2 +- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/rend-posix.c b/src/rend-posix.c index bb568552..76c590da 100644 --- a/src/rend-posix.c +++ b/src/rend-posix.c @@ -89,6 +89,9 @@ Change History (most recent first): $Log$ + Revision 1.24 2005/08/15 03:16:54 rpedde + specify interface to register + Revision 1.23 2005/01/07 06:57:59 rpedde fix minor errno problem @@ -320,7 +323,8 @@ static mStatus RegisterOneService(const char * richTextHostName, const char * serviceDomain, const mDNSu8 text[], mDNSu16 textLen, - long portNumber) + long portNumber, + mDNSInterfaceID id) { mStatus status; PosixService * thisServ; @@ -347,7 +351,7 @@ static mStatus RegisterOneService(const char * richTextHostName, port, text, textLen, NULL, 0, - mDNSInterface_Any, + id, RegistrationCallback, thisServ); } if (status == mStatus_NoError) { @@ -390,6 +394,23 @@ static void DeregisterOurServices(void) } } + +mDNSInterfaceID rend__get_interface_id(char *iface) { + PosixNetworkInterface *pni; + + if(!iface) + return mDNSInterface_Any; + + /* we'll cheat and get the underlying posix interface */ + pni = SearchForInterfaceByName(mDNSStorage, iface); + if(!pni) { + DPRINTF(E_LOG,L_REND,"Could not find interface %s - ignoring\n"); + return mDNSInterface_Any; + } + + return pni->coreIntf.mDNSInterfaceID; +} + /* * rend_callback * @@ -399,6 +420,7 @@ void rend_callback(void) { REND_MESSAGE msg; int result; int err; + mDNSInterfaceID id; DPRINTF(E_DBG,L_REND,"Processing rendezvous message\n"); @@ -413,9 +435,10 @@ void rend_callback(void) { switch(msg.cmd) { case REND_MSG_TYPE_REGISTER: + id=rend_get_interface_id(msg.interface); DPRINTF(E_DBG,L_REND,"Registering %s.%s (%d)\n",msg.name,msg.type,msg.port); RegisterOneService(msg.name,msg.type,"local.","\034Database ID=beddab1edeadbea7",29, - msg.port); + msg.port,id); rend_send_response(0); /* success */ break; case REND_MSG_TYPE_UNREGISTER: diff --git a/src/rend-unix.c b/src/rend-unix.c index 418b9931..7fe83145 100644 --- a/src/rend-unix.c +++ b/src/rend-unix.c @@ -159,7 +159,7 @@ int rend_stop(void) { * * register a rendezvous name */ -int rend_register(char *name, char *type, int port) { +int rend_register(char *name, char *type, int port, char *interface) { REND_MESSAGE msg; if((strlen(name)+1 > MAX_NAME_LEN) || (strlen(type)+1 > MAX_NAME_LEN)) { @@ -169,8 +169,11 @@ int rend_register(char *name, char *type, int port) { memset((void*)&msg,0x00,sizeof(msg)); /* shut valgrind up */ msg.cmd=REND_MSG_TYPE_REGISTER; - strcpy(msg.name,name); - strcpy(msg.type,type); + strncpy(msg.name,name,MAX_NAME_LEN-1); + strncpy(msg.type,type,MAX_NAME_LEN-1); + if(interface) + strncpy(msg.interface,interface,MAX_IFACE_NAME_LEN-1); + msg.port=port; return rend_send_message(&msg); diff --git a/src/rend-unix.h b/src/rend-unix.h index 45f79fbc..96656d4c 100644 --- a/src/rend-unix.h +++ b/src/rend-unix.h @@ -23,12 +23,16 @@ #define _REND_UNIX_H_ #define MAX_NAME_LEN 256 +/* Is there a posixly correct constant for this? */ +#define MAX_IFACE_NAME_LEN 20 + typedef struct tag_rend_message { int cmd; int port; char name[MAX_NAME_LEN]; char type[MAX_NAME_LEN]; + char interface[MAX_IFACE_NAME_LEN]; } REND_MESSAGE; #define REND_MSG_TYPE_REGISTER 0 diff --git a/src/rend.h b/src/rend.h index b5bd1962..955b70f8 100644 --- a/src/rend.h +++ b/src/rend.h @@ -25,7 +25,7 @@ extern int rend_init(char *user); extern int rend_running(void); extern int rend_stop(void); -extern int rend_register(char *name, char *type, int port); +extern int rend_register(char *name, char *type, int port, char *interface); extern int rend_unregister(char *name, char *type, int port); #endif /* _REND_H_ */