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_portmap.c
Go to the documentation of this file.
1 /*
2  * decode_portmap.c
3  *
4  * RPC portmap.
5  *
6  * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
7  *
8  * $Id: decode_portmap.c,v 1.8 2001/03/15 08:33:02 dugsong Exp $
9  */
10 
11 #include "config.h"
12 
13 #include <sys/types.h>
14 #include <rpc/rpc.h>
15 #include <rpc/pmap_prot.h>
16 
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <libnet.h>
20 #include <nids.h>
21 
22 #include "rpc.h"
23 #include "trigger.h"
24 #include "decode.h"
25 
26 int
27 decode_portmap(u_char *buf, int len, u_char *obuf, int olen)
28 {
29  XDR xdrs;
30  struct rpc_msg msg;
31  struct pmap *pm, pmap;
32  struct xid_map *xm;
33  int hdrlen;
34 
35  if ((hdrlen = rpc_decode(buf, len, &msg)) == 0)
36  return (0);
37 
38  if (msg.rm_direction == CALL &&
39  msg.rm_call.cb_prog == PMAPPROG &&
40  msg.rm_call.cb_proc == PMAPPROC_GETPORT) {
41  xdrmem_create(&xdrs, buf + hdrlen, len - hdrlen, XDR_DECODE);
42  if (xdr_pmap(&xdrs, &pmap)) {
43  if ((pm = malloc(sizeof(*pm))) != NULL) {
44  *pm = pmap;
45  xid_map_enter(msg.rm_xid, PMAPPROG, PMAPVERS,
46  PMAPPROC_GETPORT, (void *) pm);
47  }
48  }
49  xdr_destroy(&xdrs);
50  }
51  else if (msg.rm_direction == REPLY &&
52  (xm = xid_map_find(msg.rm_xid)) != NULL) {
53  if (msg.rm_reply.rp_stat == MSG_ACCEPTED &&
54  msg.acpted_rply.ar_stat == SUCCESS) {
55  pm = (struct pmap *)xm->data;
56  xdrmem_create(&xdrs, buf + hdrlen, len - hdrlen,
57  XDR_DECODE);
58  if (xdr_u_long(&xdrs, &pm->pm_port)) {
59  trigger_rpc(pm->pm_prog, pm->pm_prot,
60  pm->pm_port);
61  trigger_rpc(pm->pm_prog, pm->pm_prot,
62  0 - (int) pm->pm_port);
63  }
64  xdr_destroy(&xdrs);
65  }
66  free(xm->data);
67  memset(xm, 0, sizeof(*xm));
68  }
69  return (0);
70 }
trigger_rpc
void trigger_rpc(int program, int proto, int port)
Definition: trigger.c:527
xid_map
Definition: rpc.h:17
xid_map_enter
void xid_map_enter(u_int32_t xid, u_int32_t prog, u_int32_t vers, u_int32_t proc, void *data)
Definition: rpc.c:30
xid_map_find
struct xid_map * xid_map_find(int xid)
Definition: rpc.c:48
decode.h
rpc.h
buf
Definition: buf.h:14
trigger.h
xid_map::data
void * data
Definition: rpc.h:22
decode_portmap
int decode_portmap(u_char *buf, int len, u_char *obuf, int olen)
Definition: decode_portmap.c:27
config.h
obuf
static char obuf[4096]
Definition: trigger.c:43
rpc_decode
int rpc_decode(u_char *buf, int len, struct rpc_msg *msg)
Definition: rpc.c:70