remove dbus
[rofl0r-ixchat.git] / src / common / identd.c
blob919282ea9bc250cf35bafc00333191ab3c03b487
1 /* simple identd server for xchat under win32 */
4 static int identd_is_running = FALSE;
7 static int
8 identd (char *username)
10 int sok, read_sok, len;
11 char *p;
12 char buf[256];
13 char outbuf[256];
14 struct sockaddr_in addr;
16 sok = socket (AF_INET, SOCK_STREAM, 0);
17 if (sok == INVALID_SOCKET)
19 free (username);
20 return 0;
23 len = 1;
24 setsockopt (sok, SOL_SOCKET, SO_REUSEADDR, (char *) &len, sizeof (len));
26 memset (&addr, 0, sizeof (addr));
27 addr.sin_family = AF_INET;
28 addr.sin_port = htons (113);
30 if (bind (sok, (struct sockaddr *) &addr, sizeof (addr)) == SOCKET_ERROR)
32 closesocket (sok);
33 free (username);
34 return 0;
37 if (listen (sok, 1) == SOCKET_ERROR)
39 closesocket (sok);
40 free (username);
41 return 0;
44 len = sizeof (addr);
45 read_sok = accept (sok, (struct sockaddr *) &addr, &len);
46 closesocket (sok);
47 if (read_sok == INVALID_SOCKET)
49 free (username);
50 return 0;
53 identd_is_running = FALSE;
55 snprintf (outbuf, sizeof (outbuf), "%%\tServicing ident request from %s\n",
56 inet_ntoa (addr.sin_addr));
57 PrintText (current_sess, outbuf);
59 recv (read_sok, buf, sizeof (buf) - 1, 0);
60 buf[sizeof (buf) - 1] = 0; /* ensure null termination */
62 p = strchr (buf, ',');
63 if (p)
65 snprintf (outbuf, sizeof (outbuf) - 1, "%d, %d : USERID : UNIX : %s\r\n",
66 atoi (buf), atoi (p + 1), username);
67 outbuf[sizeof (outbuf) - 1] = 0; /* ensure null termination */
68 send (read_sok, outbuf, strlen (outbuf), 0);
71 sleep (1);
72 closesocket (read_sok);
73 free (username);
75 return 0;
78 static void
79 identd_start (char *username)
81 DWORD tid;
83 if (identd_is_running == FALSE)
85 identd_is_running = TRUE;
86 CloseHandle (CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) identd,
87 strdup (username), 0, &tid));