dsniff  2.4b2
About: A collection of tools for network auditing
  Fossies Dox: dsniff-2.4b2.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

decode_irc.c
Go to the documentation of this file.
1 /*
2  * decode_irc.c
3  *
4  * Internet Relay Chat.
5  *
6  * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
7  *
8  * $Id: decode_irc.c,v 1.6 2001/03/15 08:33:01 dugsong Exp $
9  */
10 
11 #include "config.h"
12 
13 #include <sys/types.h>
14 
15 #include <stdio.h>
16 #include <string.h>
17 
18 #include "buf.h"
19 #include "decode.h"
20 
21 int
22 decode_irc(u_char *buf, int len, u_char *obuf, int olen)
23 {
24  struct buf *line, inbuf, outbuf;
25  int i, got_auth;
26 
27  buf_init(&inbuf, buf, len);
28  buf_init(&outbuf, obuf, olen);
29  got_auth = 0;
30 
31  while ((i = buf_index(&inbuf, "\n", 1)) != -1) {
32  line = buf_tok(&inbuf, NULL, i);
33  buf_skip(&inbuf, 1);
34 
35  if (i > 0 && line->base[i - 1] == '\r')
36  line->end--;
37  line->base[line->end] = '\0';
38 
39  if (buf_cmp(&inbuf, ";", 1) == 0) {
40  if ((i = buf_index(line, " ", 1)) < 0)
41  continue;
42  buf_skip(line, i + 1);
43  }
44  if (buf_cmp(line, "USER ", 5) == 0 ||
45  buf_cmp(line, "NICK ", 5) == 0) {
47  buf_putf(&outbuf, "%s\n", buf_ptr(line));
48  }
49  else if (buf_cmp(line, "PASS ", 5) == 0 ||
50  buf_cmp(line, "OPER ", 5) == 0) {
52  buf_putf(&outbuf, "%s\n", buf_ptr(line));
53  got_auth = 1;
54  }
55  else if (buf_cmp(line, "MODE ", 5) == 0 &&
56  buf_index(line, " +k ", 4) != -1) {
58  buf_putf(&outbuf, "%s\n", buf_ptr(line));
59  got_auth = 1;
60  }
61  else if (buf_cmp(line, "JOIN ", 5) == 0) {
62  buf_skip(line, 5);
63  if ((i = buf_index(line, " ", 1)) < 0)
64  continue;
65  buf_skip(line, i + 1);
66  if (buf_len(line) < 1)
67  continue;
69  buf_putf(&outbuf, "%s\n", buf_ptr(line));
70  got_auth = 1;
71  }
72  }
73  buf_end(&outbuf);
74 
75  return (got_auth ? buf_len(&outbuf) : 0);
76 }
buf_putf
int buf_putf(buf_t buf, const char *fmt,...)
Definition: buf.c:106
buf_rewind
#define buf_rewind(b)
Definition: buf.h:48
buf_init
void buf_init(buf_t buf, u_char *data, int len)
Definition: buf.c:24
buf_end
void buf_end(buf_t buf)
Definition: buf.c:121
decode.h
buf.h
buf
Definition: buf.h:14
buf_tok
buf_t buf_tok(buf_t buf, void *sep, int len)
Definition: buf.c:167
buf_ptr
#define buf_ptr(b)
Definition: buf.h:31
line
Definition: sshow.c:62
buf_cmp
int buf_cmp(buf_t buf, void *ptr, int len)
Definition: buf.c:158
buf_skip
#define buf_skip(b, l)
Definition: buf.h:47
config.h
obuf
static char obuf[4096]
Definition: trigger.c:43
buf_len
#define buf_len(b)
Definition: buf.h:34
decode_irc
int decode_irc(u_char *buf, int len, u_char *obuf, int olen)
Definition: decode_irc.c:22
buf_index
int buf_index(buf_t buf, void *ptr, int len)
Definition: buf.c:128