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