[02/12] unix: Add find_unix_sk_by_name()

Submitted by Kirill Tkhai on April 29, 2016, 2:35 p.m.

Details

Message ID 146194052518.9179.12567503950226422046.stgit@pro
State Rejected
Series "Support for packet's msg_name in receive queue of promiscous DGRAM sockets"
Headers show

Commit Message

Kirill Tkhai April 29, 2016, 2:35 p.m.
Add a helper for searching a socket's unix_sk_desc by its name.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/sk-unix.c |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/sk-unix.c b/criu/sk-unix.c
index 4ad21af..d1f4c33 100644
--- a/criu/sk-unix.c
+++ b/criu/sk-unix.c
@@ -97,6 +97,24 @@  static struct unix_sk_listen_icon *lookup_unix_listen_icons(int peer_ino)
 	return NULL;
 }
 
+static struct unix_sk_desc *find_unix_sk_by_name(const char *name, int namelen)
+{
+	struct unix_sk_desc *sk;
+
+	namelen -= sizeof(unsigned short);
+	if (namelen <= 0)
+		return NULL;
+	/* Skip sun_family */
+	name += sizeof(unsigned short);
+
+	list_for_each_entry(sk, &unix_sockets, list) {
+		if (namelen == sk->namelen && memcmp(name, sk->name, namelen) == 0)
+			return sk;
+	}
+
+	return NULL;
+}
+
 static void show_one_unix(char *act, const struct unix_sk_desc *sk)
 {
 	pr_debug("\t%s: ino %#x peer_ino %#x family %4d type %4d state %2d name %s\n",