TMdnsdRecord *srv_to_host;
TMdnsdRecord *txt_for_srv;
+ TMdnsdRecord *ptr_to_srvtype;
TMdnsdRecord *ptr_to_srv;
TMdnsdState state;
{
int id = 1;
char *pos;
- char *end = NULL;
+ char *end = NULL;
char *ret = NULL;
pos = strrchr (name, '-');
id = strtol (pos + 1, &end, 10);
if (*end == '\0') {
*pos = '\0';
- } else {
+ } else {
id = 1;
- }
+ }
}
id += 1;
/* conflict handling */
-void handle_conflict (TMdnsdRecord *record, uint8_t *name, int UNUSED(type), void *arg)
+void handle_conflict (TMdnsdRecord *record, char *name, int UNUSED(type), void *arg)
{
ServiceInfo *info = (ServiceInfo *) arg;
char *newname;
if (record == info->srv_to_host) {
info->srv_to_host = NULL;
- }
+ }
if (record == info->txt_for_srv) {
info->txt_for_srv = NULL;
- }
+ }
fprintf (stderr, "conflicting name \"%s\". trying %s\n",
name, info->servicename);
- /* The hostname was changed, so go back to probe state */
+ /* The hostname was changed, so go back to probe state */
info->state = MDNSD_PROBE;
}
int msock ()
{
int sock_fd;
- int flag = 1;
- int ittl = 255;
+ int flag = 1;
+ int ittl = 255;
char ttl = 255;
struct sockaddr_in in;
struct ip_mreq mc;
if ((sock_fd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) {
return 0;
- }
+ }
setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, (char*) &flag, sizeof (flag));
if (bind (sock_fd, (struct sockaddr*) &in, sizeof (in))) {
void request_ip_addresses (ServiceInfo *info)
{
char revlookup[256];
- char hostlocal[256];
+ char hostlocal[256];
struct in_addr ip;
int num_ips = 0;
info->host_to_ip = MdnsdAllocUnique(info->mdnsd, hostlocal,
QTYPE_A, 120, handle_conflict, info);
}
- MdnsdSetRaw (info->mdnsd, info->host_to_ip, (uint8_t *) &ip, 4);
+ MdnsdSetRaw (info->mdnsd, info->host_to_ip, (char *) &ip, 4);
if (!info->ip_to_host) {
info->ip_to_host = MdnsdAllocUnique(info->mdnsd, revlookup,
} else {
if (info->host_to_ip) {
MdnsdDone (service_info.mdnsd, info->host_to_ip);
- }
+ }
if (info->ip_to_host) {
MdnsdDone (service_info.mdnsd, info->ip_to_host);
- }
+ }
info->host_to_ip = NULL;
info->ip_to_host = NULL;
void request_service (ServiceInfo *info, int stage)
{
uint8_t *packet;
- char servlocal[256];
- char hostlocal[256];
+ char servlocal[256];
+ char hostlocal[256];
int len = 0;
sprintf (servlocal, "%s._http._tcp.local.",
}
MdnsdSetHost (info->mdnsd, info->ptr_to_srv, servlocal);
+ if (!info->ptr_to_srvtype) {
+ info->ptr_to_srvtype = MdnsdAllocShared (info->mdnsd, "_services._dns-sd._udp.local.",
+ QTYPE_PTR, 4500);
+ }
+ MdnsdSetHost (info->mdnsd, info->ptr_to_srvtype, "_http._tcp.local.");
+
if (info->ip) {
fprintf (stderr, "Announcing \"%s.local\" to %s:%d\n",
info->servicename ? info->servicename : info->hostname,
info->ip, info->port);
- }
+ }
break;
default:
uint16_t port;
struct timeval tv;
int bsize;
- int ssize = sizeof(struct sockaddr_in);
+ int ssize = sizeof(struct sockaddr_in);
uint8_t buf[MAX_PACKET_LEN];
struct sockaddr_in from;
- struct sockaddr_in to;
+ struct sockaddr_in to;
int idx;
- int s;
+ int s;
struct in_addr remote_ip;
char *value;
int polltime = 0;
if(argc < 4)
{
- fprintf (stderr, "usage: mhttp <ip> <port> <key1>=<value1> <key2>=<value2> ...\n");
- fprintf (stderr, " <ip> The IP address to promote\n");
- fprintf (stderr, " <port> is the port number of the service to be advertized\n");
+ fprintf (stderr, "usage: mhttp <hostname> <ip> <port> <key1>=<value1> <key2>=<value2> ...\n");
+ fprintf (stderr, " <hostname> The hostname which shall be promoted as 'hostname.local'\n");
+ fprintf (stderr, " <ip> The IP address to promote\n");
+ fprintf (stderr, " <port> is the port number of the service to be advertized\n");
fprintf (stderr, " <key>=<value> are the keys that get embedded into the TXT record.\n");
return -1;
}
service_info.mdnsd = MdnsdNew (1, 1000);
- //gethostname (service_info.hostname, HOSTNAMESIZE);
- sprintf(service_info.hostname, "reinhardt");
+ //gethostname (service_info.hostname, HOSTNAMESIZE);
+ strncpy(service_info.hostname, argv[1], HOSTNAMESIZE-1);
service_info.hostname[HOSTNAMESIZE-1] = '\0';
+
if (strchr (service_info.hostname, '.'))
strchr (service_info.hostname, '.')[0] = '\0';
service_info.servicename = NULL;
- service_info.ip = strdup(argv[1]);
+ service_info.ip = strdup(argv[2]);
service_info.announce_ip.s_addr = inet_addr(service_info.ip);
service_info.host_to_ip = NULL;
service_info.ip_to_host = NULL;
- service_info.port = atoi(argv[2]);
+ service_info.port = atoi(argv[3]);
service_info.metadata = SHashInit (11);
- for (idx = 2; idx < argc; idx++) {
+ for (idx = 3; idx < argc; idx++) {
value = index (argv[idx], '=');
if (value) {
value[0] = '\0';
}
}
+ service_info.ptr_to_srvtype = NULL;
service_info.ptr_to_srv = NULL;
service_info.srv_to_host = NULL;
service_info.txt_for_srv = NULL;
{
case MDNSD_PROBE:
- if (service_info.ptr_to_srv) {
+ if (service_info.ptr_to_srvtype) {
+ MdnsdDone (service_info.mdnsd, service_info.ptr_to_srvtype);
+ }
+
+ if (service_info.ptr_to_srv) {
MdnsdDone (service_info.mdnsd, service_info.ptr_to_srv);
- }
+ }
- if (service_info.srv_to_host) {
+ if (service_info.srv_to_host) {
MdnsdDone (service_info.mdnsd, service_info.srv_to_host);
- }
+ }
if (service_info.txt_for_srv) {
MdnsdDone (service_info.mdnsd, service_info.txt_for_srv);
- }
+ }
+ service_info.ptr_to_srvtype = NULL;
service_info.ptr_to_srv = NULL;
service_info.srv_to_host = NULL;
service_info.txt_for_srv = NULL;
if (service_info.host_to_ip) {
MdnsdDone (service_info.mdnsd, service_info.host_to_ip);
- }
+ }
if (service_info.ip_to_host) {
MdnsdDone (service_info.mdnsd, service_info.ip_to_host);
- }
+ }
service_info.host_to_ip = NULL;
service_info.ip_to_host = NULL;
polltime = cur_tv.tv_sec * 1000 + cur_tv.tv_usec / 1000;
if (polltime >= 756) {
polltime = 756;
- }
+ }
} else {
cur_tv = *MdnsdGetMaxSleepTime (service_info.mdnsd);
polltime = cur_tv.tv_sec * 1000 + cur_tv.tv_usec / 1000;
if (polltime >= 756 - msecs) {
polltime = 756 - msecs;
- }
+ }
}
} else {
tv = *MdnsdGetMaxSleepTime (service_info.mdnsd);
if (service_info.state == MDNSD_SHUTDOWN) {
break;
- }
+ }
}
MdnsdShutdown (service_info.mdnsd);