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