Add missing '.'
[dragonfly.git] / contrib / ipfilter / ip_netbios_pxy.c
blobee9b0c4f118fc1a28e814d05628196c8af9c99a6
1 /*
2 * Simple netbios-dgm transparent proxy for in-kernel use.
3 * For use with the NAT code.
4 * $Id: ip_netbios_pxy.c,v 1.1.2.3 2002/01/09 09:28:37 darrenr Exp $
5 */
7 /*-
8 * Copyright (c) 2002 Paul J. Ledbetter III
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
32 * $Id: ip_netbios_pxy.c,v 1.1.2.3 2002/01/09 09:28:37 darrenr Exp $
35 #define IPF_NETBIOS_PROXY
37 int ippr_netbios_init __P((void));
38 int ippr_netbios_out __P((fr_info_t *, ip_t *, ap_session_t *, nat_t *));
40 static frentry_t netbiosfr;
43 * Initialize local structures.
45 int ippr_netbios_init()
47 bzero((char *)&netbiosfr, sizeof(netbiosfr));
48 netbiosfr.fr_ref = 1;
49 netbiosfr.fr_flags = FR_INQUE|FR_PASS|FR_QUICK|FR_KEEPSTATE;
50 return 0;
53 int ippr_netbios_out(fin, ip, aps, nat)
54 fr_info_t *fin;
55 ip_t *ip;
56 ap_session_t *aps;
57 nat_t *nat;
59 char dgmbuf[6];
61 int off, dlen;
62 udphdr_t *udp;
63 mb_t *m;
65 m = *(mb_t **)fin->fin_mp;
66 off = fin->fin_hlen + sizeof(udphdr_t);
67 #if SOLARIS
68 dlen = msgdsize(m);
69 #else
70 dlen = mbufchainlen(m);
71 #endif
72 dlen -= off;
75 * no net bios datagram could possibly be shorter than this
77 if (dlen < 11)
78 return 0;
80 udp = (udphdr_t *)fin->fin_dp;
82 /*
83 * move past the
84 * ip header;
85 * udp header;
86 * 4 bytes into the net bios dgm header.
87 * According to rfc1002, this should be the exact location of
88 * the source address/port
90 off += 4;
92 /* Copy NATed source Address/port*/
93 dgmbuf[0] = (char)((ip->ip_src.s_addr ) &0xFF);
94 dgmbuf[1] = (char)((ip->ip_src.s_addr >> 8) &0xFF);
95 dgmbuf[2] = (char)((ip->ip_src.s_addr >> 16)&0xFF);
96 dgmbuf[3] = (char)((ip->ip_src.s_addr >> 24)&0xFF);
98 dgmbuf[4] = (char)((udp->uh_sport )&0xFF);
99 dgmbuf[5] = (char)((udp->uh_sport >> 8)&0xFF);
101 /* replace data in packet */
102 #if SOLARIS
103 copyin_mblk(m, off, sizeof(dgmbuf), dgmbuf);
104 #else
105 m_copyback(m, off, sizeof(dgmbuf), dgmbuf);
106 #endif
108 return 0;