specify interface to register

This commit is contained in:
Ron Pedde 2005-08-15 03:16:54 +00:00
parent 1570844d6d
commit fa48f1175b
4 changed files with 37 additions and 7 deletions

View File

@ -89,6 +89,9 @@
Change History (most recent first): Change History (most recent first):
$Log$ $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 Revision 1.23 2005/01/07 06:57:59 rpedde
fix minor errno problem fix minor errno problem
@ -320,7 +323,8 @@ static mStatus RegisterOneService(const char * richTextHostName,
const char * serviceDomain, const char * serviceDomain,
const mDNSu8 text[], const mDNSu8 text[],
mDNSu16 textLen, mDNSu16 textLen,
long portNumber) long portNumber,
mDNSInterfaceID id)
{ {
mStatus status; mStatus status;
PosixService * thisServ; PosixService * thisServ;
@ -347,7 +351,7 @@ static mStatus RegisterOneService(const char * richTextHostName,
port, port,
text, textLen, text, textLen,
NULL, 0, NULL, 0,
mDNSInterface_Any, id,
RegistrationCallback, thisServ); RegistrationCallback, thisServ);
} }
if (status == mStatus_NoError) { 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 * rend_callback
* *
@ -399,6 +420,7 @@ void rend_callback(void) {
REND_MESSAGE msg; REND_MESSAGE msg;
int result; int result;
int err; int err;
mDNSInterfaceID id;
DPRINTF(E_DBG,L_REND,"Processing rendezvous message\n"); DPRINTF(E_DBG,L_REND,"Processing rendezvous message\n");
@ -413,9 +435,10 @@ void rend_callback(void) {
switch(msg.cmd) { switch(msg.cmd) {
case REND_MSG_TYPE_REGISTER: 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); 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, RegisterOneService(msg.name,msg.type,"local.","\034Database ID=beddab1edeadbea7",29,
msg.port); msg.port,id);
rend_send_response(0); /* success */ rend_send_response(0); /* success */
break; break;
case REND_MSG_TYPE_UNREGISTER: case REND_MSG_TYPE_UNREGISTER:

View File

@ -159,7 +159,7 @@ int rend_stop(void) {
* *
* register a rendezvous name * 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; REND_MESSAGE msg;
if((strlen(name)+1 > MAX_NAME_LEN) || (strlen(type)+1 > MAX_NAME_LEN)) { 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 */ memset((void*)&msg,0x00,sizeof(msg)); /* shut valgrind up */
msg.cmd=REND_MSG_TYPE_REGISTER; msg.cmd=REND_MSG_TYPE_REGISTER;
strcpy(msg.name,name); strncpy(msg.name,name,MAX_NAME_LEN-1);
strcpy(msg.type,type); strncpy(msg.type,type,MAX_NAME_LEN-1);
if(interface)
strncpy(msg.interface,interface,MAX_IFACE_NAME_LEN-1);
msg.port=port; msg.port=port;
return rend_send_message(&msg); return rend_send_message(&msg);

View File

@ -23,12 +23,16 @@
#define _REND_UNIX_H_ #define _REND_UNIX_H_
#define MAX_NAME_LEN 256 #define MAX_NAME_LEN 256
/* Is there a posixly correct constant for this? */
#define MAX_IFACE_NAME_LEN 20
typedef struct tag_rend_message { typedef struct tag_rend_message {
int cmd; int cmd;
int port; int port;
char name[MAX_NAME_LEN]; char name[MAX_NAME_LEN];
char type[MAX_NAME_LEN]; char type[MAX_NAME_LEN];
char interface[MAX_IFACE_NAME_LEN];
} REND_MESSAGE; } REND_MESSAGE;
#define REND_MSG_TYPE_REGISTER 0 #define REND_MSG_TYPE_REGISTER 0

View File

@ -25,7 +25,7 @@
extern int rend_init(char *user); extern int rend_init(char *user);
extern int rend_running(void); extern int rend_running(void);
extern int rend_stop(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); extern int rend_unregister(char *name, char *type, int port);
#endif /* _REND_H_ */ #endif /* _REND_H_ */