xorl %eax, %eax

irssi CTCP VERSION patch

with 4 comments

Well, I couldn’t sleep and I wrote a tiny little patch for irssi that changes the CTCP VERSION replies at will using a file at ~/.irssi/. It’s not anything special but if anyone is interested it’s this…

--- src/irc/core/ctcp.h 2009-03-31 23:50:02.000000000 +0300
+++ src/irc/core/ctcp.h.new     2009-04-25 05:57:49.000000000 +0300
@@ -1,6 +1,9 @@
 #ifndef __CTCP_H
 #define __CTCP_H

+#define FUCKING_CTCP_VER_FILE "/home/xorl/.irssi/os_huhu_file.txt"
+#define AWESOMENESS 313
 /* Register/unregister CTCP command, so it shows in CTCP CLIENTINFO */
 void ctcp_register(const char *name);
 void ctcp_unregister(const char *name);

--- src/irc/core/ctcp.c 2009-03-31 23:50:02.000000000 +0300
+++ src/irc/core/ctcp.c.new     2009-04-25 05:57:43.000000000 +0300
@@ -29,14 +29,42 @@
 #include "servers-idle.h"
 #include "ignore.h"
 #include "ctcp.h"
+#include <sys/types.h>

 typedef struct {
        char *name;
         int refcount;

+static unsigned char ctcp_os_version_buf[AWESOMENESS];
 static GSList *ctcp_cmds;

+static void
+       FILE *fd;
+       size_t len = 0;
+       unsigned char c;
+       memset(&ctcp_os_version_buf, 0, sizeof(ctcp_os_version_buf));
+       fd = fopen(FUCKING_CTCP_VER_FILE, "r");
+       if (fd == NULL)
+         snprintf(ctcp_os_version_buf, sizeof(ctcp_os_version_buf), "Choo Choo IRC");
+       else
+       {
+         do {
+               c = getc(fd);
+               ctcp_os_version_buf[len] = c;
+               len++;
+         } while (c != '\n' && c != EOF && len < sizeof(ctcp_os_version_buf));
+           ctcp_os_version_buf[--len] = '';
+       }
+       if (fd)
+         fclose(fd);
+       return;
 static CTCP_CMD_REC *ctcp_cmd_find(const char *name)
        GSList *tmp;
@@ -167,8 +195,8 @@ static void ctcp_send_parsed_reply(IRC_S
 static void ctcp_version(IRC_SERVER_REC *server, const char *data,
                         const char *nick)
-       ctcp_send_parsed_reply(server, nick, "VERSION",
-                              settings_get_str("ctcp_version_reply"));
+       are_you_talking_to_me();
+       ctcp_send_parsed_reply(server, nick, "VERSION", ctcp_os_version_buf);

 /* CTCP time */

I wrote it in 10 minutes or so.. So, it’s not perfect. Nevertheless, if you want to use it then you’ll have to compile it with 0.8.13 release of irssi.

P.S.: ithilgore… no bzero() man :-P

P.S.2: I just realized that wordpress parses and removes the NULL (slash zero) character. Look at ctcp_os_version_buf[–len] = ”; there was a slash zero there… lol

Written by xorl

April 25, 2009 at 03:09

4 Responses

Subscribe to comments with RSS.

  1. Can’t you just control this using the ctcp_version_reply setting?


    April 25, 2009 at 03:43

  2. Of course, but I was bored and I wanted to do something fun.


    April 25, 2009 at 04:17

  3. memset(&ctcp_os_version_buf, 0, sizeof(ctcp_os_version_buf)); => Do not use the address of the array, use the array name or the address of the first element of the array. The C standard does not guarantee that &array is the same as array or &array[0] (however array == &array[0]) even though in most cases (if not all) that is true. On top of that, &ctcp_os_version_buf is of type unsigned char (*)[AWESOMENESS] and ctcp_os_version_buf is an array of AWESOMENESS unsigned chars. That said, the two are incompatible types. The implicit conversion to void * silences the warning.


    April 27, 2009 at 21:57

  4. man… i love your comments… You also forgot to write about ‘unsigned char c’ that you told me on IRC :-P
    Of course you’re right but this is not production code and I don’t think that any of these is by any chance security bug. Nevertheless, if anyone applied this patch.. update it by replacing:
    unsigned char c;
    int c;
    memset(&ctcp_os_version_buf, 0, sizeof(ctcp_os_version_buf));
    memset(ctcp_os_version_buf, 0, sizeof(ctcp_os_version_buf));
    When it comes to programming.. I’m unable argue with you sin :-P


    April 27, 2009 at 22:33

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s