All pastes #2689481 Raw Edit

Stuff

public unlisted c v1 · immutable
#2689481 ·published 2014-03-31 09:14 UTC
rendered paste body
#include <unistd.h>#include <sys/types.h>#include <sys/socket.h>#include <netdb.h>#include <stdio.h>#include <stdlib.h>#include <string.h>const char \    *bot_owner = "Alberto",    *nick = "MrRoboto",    *serv = "irc.sylnt.us",    *chan = "#";int main() {    int ret;    char buf[512];    int sock;    struct addrinfo hints, *ai;    memset(&hints, 0, sizeof(struct addrinfo));    hints.ai_family = AF_UNSPEC;    hints.ai_socktype = SOCK_STREAM;    hints.ai_protocol = IPPROTO_TCP;    if (ret = getaddrinfo(serv, "6667", &hints, &ai)) {        puts(gai_strerror(ret));        return 1;    }    sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);    if (ret = connect(sock, ai->ai_addr, ai->ai_addrlen)) {        puts(gai_strerror(ret));        return 1;    }    freeaddrinfo(ai);    sprintf(buf, "USER %s 0 * :%s\r\n", nick, bot_owner);    send(sock, buf, strlen(buf), 0);    sprintf(buf, "NICK %s\r\n", nick);    send(sock, buf, strlen(buf), 0);    while (recv(sock, buf, 512, 0) > 0) {        fputs(buf, stdout);        if (!strncmp(buf, "PING ", 5)) {            buf[1] = 'O';            send(sock, buf, strlen(buf), 0);        }        if (buf[0] != ':') continue;        if (!strncmp(strchr(buf, ' ') + 1, "001", 3)) {            sprintf(buf, "JOIN %s\r\n", chan);            send(sock, buf, strlen(buf), 0);        } else if (!strncmp(strchr(buf, ' ') + 1, "PRIVMSG", 7)) {            if (strncmp(strchr(buf + 1, ':') + 1, nick, strlen(nick))) continue;            sprintf(buf, "PRIVMSG %s :Someone just spoke to me!\r\n", chan);            send(sock, buf, strlen(buf), 0);        }    }    close(sock);    return 0;}