[v2,05/15] unix: Add find_unix_sk_by_name()

Submitted by Kirill Tkhai on May 27, 2016, 1:06 p.m.

Details

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

Commit Message

Kirill Tkhai May 27, 2016, 1:06 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 40cb9db..58aba82 100644
--- a/criu/sk-unix.c
+++ b/criu/sk-unix.c
@@ -114,6 +114,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",