]>
git.saurik.com Git - apple/network_cmds.git/blob - alias/alias_cuseeme.c
cb7478abf5f44aeaab08364cb06e73367d9d5875
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
25 * with the aid of code written by
26 * Junichi SATOH <junichi@astec.co.jp> 1996, 1997.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the distribution.
38 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
39 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
42 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
44 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
46 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
47 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * $FreeBSD: src/lib/libalias/alias_cuseeme.c,v 1.2.2.2 2000/10/31 08:48:21 ru Exp $
54 #include <sys/types.h>
55 #include <netinet/in_systm.h>
56 #include <netinet/in.h>
57 #include <netinet/ip.h>
58 #include <netinet/udp.h>
60 #include "alias_local.h"
62 /* CU-SeeMe Data Header */
64 u_int16_t dest_family
;
76 /* Open Continue Header */
78 u_int16_t client_count
; /* Number of client info structs */
81 char reserved
[4]; /* flags, version stuff, etc */
84 /* client info structures */
86 u_int32_t address
; /* Client address */
87 char reserved
[8]; /* Flags, pruning bitfield, packet counts etc */
91 AliasHandleCUSeeMeOut(struct ip
*pip
, struct alias_link
*link
)
95 ud
= (struct udphdr
*)((char *)pip
+ (pip
->ip_hl
<< 2));
96 if (ntohs(ud
->uh_ulen
) - sizeof(struct udphdr
) >= sizeof(struct cu_header
)) {
98 struct alias_link
*cu_link
;
100 cu
= (struct cu_header
*)(ud
+ 1);
102 cu
->addr
= (u_int32_t
)GetAliasAddress(link
).s_addr
;
104 cu_link
= FindUdpTcpOut(pip
->ip_src
, GetDestAddress(link
),
105 ud
->uh_dport
, 0, IPPROTO_UDP
, 1);
109 PunchFWHole(cu_link
);
115 AliasHandleCUSeeMeIn(struct ip
*pip
, struct in_addr original_addr
)
117 struct in_addr alias_addr
;
119 struct cu_header
*cu
;
120 struct oc_header
*oc
;
121 struct client_info
*ci
;
125 alias_addr
.s_addr
= pip
->ip_dst
.s_addr
;
126 ud
= (struct udphdr
*)((char *)pip
+ (pip
->ip_hl
<< 2));
127 cu
= (struct cu_header
*)(ud
+ 1);
128 oc
= (struct oc_header
*)(cu
+ 1);
129 ci
= (struct client_info
*)(oc
+ 1);
130 end
= (char *)ud
+ ntohs(ud
->uh_ulen
);
132 if ((char *)oc
<= end
) {
134 cu
->dest_addr
= (u_int32_t
)original_addr
.s_addr
;
135 if(ntohs(cu
->data_type
) == 101)
136 /* Find and change our address */
137 for(i
= 0; (char *)(ci
+ 1) <= end
&& i
< oc
->client_count
; i
++, ci
++)
138 if(ci
->address
== (u_int32_t
)alias_addr
.s_addr
) {
139 ci
->address
= (u_int32_t
)original_addr
.s_addr
;