Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Aug 2007 23:26:43 GMT
From:      Fredrik Lindberg <fli@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 125246 for review
Message-ID:  <200708162326.l7GNQhd3038431@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=125246

Change 125246 by fli@fli_nexus on 2007/08/16 23:26:19

	- Add mdns_cache_flush() - flushes the cache
	- Add mdns_cache_view() - view cache content

Affected files ...

.. //depot/projects/soc2007/fli-mdns_sd/libmdns/libmdns.c#3 edit
.. //depot/projects/soc2007/fli-mdns_sd/libmdns/mdns.h#3 edit

Differences ...

==== //depot/projects/soc2007/fli-mdns_sd/libmdns/libmdns.c#3 (text+ko) ====

@@ -707,6 +707,94 @@
 	return (0);
 }
 
+int
+mdns_cache_flush(struct mdns *m, unsigned int ifidx)
+{
+	int mid, error;
+	struct mdns_msg *mm;
+	struct mipc_cache_flush mcf;
+
+	mcf.mcf_ifidx = ifidx;
+
+	mid = docmd(m, MIM_CACHE_FLUSH, 1, &mcf,
+	    sizeof(struct mipc_cache_flush));
+	if (mid < 0)
+		return (-1);
+
+	mm = msg_wait(m, mid, NULL);
+	if (mm == NULL)
+		return (-1);
+
+	error = errormsg(mm);
+	msg_free(mm);
+	if (error >= 0)
+		return (-1);
+	return (0);
+}
+
+int
+mdns_cache_list(struct mdns *m, unsigned int ifidx, struct mdns_cache **mc)
+{
+	int mid, offset, error, validres;
+	char *pkg;
+	size_t sz;
+	struct mdns_msg *mm;
+	struct mdns_cache *mcp;
+	struct mipc_cache *mic;
+	struct mipc_cache_list mcl;
+
+	if (ifidx == 0)
+		return (-1);
+
+	mcl.mcl_ifidx = ifidx;
+	mid = docmd(m, MIM_CACHE_LIST, 1, &mcl, sizeof(struct mipc_cache_list));
+	if (mid < 0)
+		return (-1);
+
+	sz = 0;
+	offset = 0;
+	mcp = NULL;
+	validres = 1;
+	do {
+		mm = msg_wait(m, mid, NULL);
+
+		if (mm->mm_msgtype == MIM_CACHE) {
+			mic = (struct mipc_cache *)mm->mm_buf;
+			pkg = mm->mm_buf + sizeof(struct mipc_cache);
+
+			mcp = realloc(mcp,
+			    (offset + 1) * sizeof(struct mdns_cache));
+			mcp[offset].mc_rrset.mr_class = mic->mc_class;
+			mcp[offset].mc_rrset.mr_type = mic->mc_type;
+			mcp[offset].mc_rrset.mr_ttl = mic->mc_ttl;
+			mcp[offset].mc_rrset.mr_reslen = mic->mc_reslen;
+			mcp[offset].mc_rrset.mr_ifidx = ifidx;
+			mcp[offset].mc_rrset.mr_family = AF_UNSPEC;
+			mcp[offset].mc_ttl_left = mic->mc_ttl_left;
+
+			memcpy(mcp[offset].mc_rrset.mr_name, pkg,
+			    mic->mc_reclen * sizeof(wchar_t));
+			mcp[offset].mc_rrset.mr_name[mic->mc_reclen] = L'\0';
+
+			pkg += (mic->mc_reclen * sizeof(wchar_t));
+
+			mcp[offset].mc_rrset.mr_res = malloc(mic->mc_reslen);
+			memcpy(mcp[offset].mc_rrset.mr_res, pkg,
+			    mic->mc_reslen);
+
+			offset++;
+		}
+		else if (mm->mm_msgtype == MIM_ACK)
+			validres = 0;
+		else if ((error = errormsg(mm)) >= 0)
+			validres = 0;
+		msg_free(mm);
+	} while (validres);
+
+	*mc = mcp;
+	return (offset);
+}
+
 static int
 errormsg(struct mdns_msg *mm)
 {

==== //depot/projects/soc2007/fli-mdns_sd/libmdns/mdns.h#3 (text+ko) ====

@@ -86,6 +86,17 @@
 #define MDNS_RES_DEFAULT (0)	/* Default resource type */
 #define MDNS_RES_POINTER (-1)	/* Resource is a resource set pointer */
 
+/* Cache entry */
+struct mdns_cache {
+	uint32_t		mc_ttl_left;
+	struct mdns_rrset	mc_rrset;
+};
+
+int		mdns_cache_list(struct mdns *, unsigned int,
+    struct mdns_cache **);
+/* Request to flush cache */
+int		mdns_cache_flush(struct mdns *, unsigned int);
+
 /* Array to class (integer) translation */
 int		mdns_atoc(const char *);
 /* Class (integer) to array translation */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200708162326.l7GNQhd3038431>