]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/ipfilter/lib/getnattype.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / ipfilter / lib / getnattype.c
1 /*      $FreeBSD$       */
2
3 /*
4  * Copyright (C) 2002-2004 by Darren Reed.
5  *
6  * See the IPFILTER.LICENCE file for details on licencing.
7  *
8  * Added redirect stuff and a variety of bug fixes. (mcn@EnGarde.com)
9  */
10 #include "ipf.h"
11 #include "kmem.h"
12
13 #if !defined(lint)
14 static const char rcsid[] = "@(#)$Id: getnattype.c,v 1.3.2.2 2006/07/14 06:12:24 darrenr Exp $";
15 #endif
16
17
18 /*
19  * Get a nat filter type given its kernel address.
20  */
21 char *getnattype(nat, alive)
22 nat_t *nat;
23 int alive;
24 {
25         static char unknownbuf[20];
26         ipnat_t *ipn, ipnat;
27         char *which;
28         int type;
29
30         if (!nat)
31                 return "???";
32         if (alive) {
33                 type = nat->nat_redir;
34         } else {
35                 ipn = nat->nat_ptr;
36                 if (kmemcpy((char *)&ipnat, (long)ipn, sizeof(ipnat)))
37                         return "!!!";
38                 type = ipnat.in_redir;
39         }
40
41         switch (type)
42         {
43         case NAT_MAP :
44                 which = "MAP";
45                 break;
46         case NAT_MAPBLK :
47                 which = "MAP-BLOCK";
48                 break;
49         case NAT_REDIRECT :
50                 which = "RDR";
51                 break;
52         case NAT_BIMAP :
53                 which = "BIMAP";
54                 break;
55         default :
56                 sprintf(unknownbuf, "unknown(%04x)", type & 0xffffffff);
57                 which = unknownbuf;
58                 break;
59         }
60         return which;
61 }