- Leftover 2 from 42210
[reactos.git] / reactos / lib / drivers / ip / transport / tcp / if.c
1 /*
2 * Copyright (c) 1997-1998 University of Utah and the Flux Group.
3 * All rights reserved.
4 *
5 * This file is part of the Flux OSKit. The OSKit is free software, also known
6 * as "open source;" you can redistribute it and/or modify it under the terms
7 * of the GNU General Public License (GPL), version 2, as published by the Free
8 * Software Foundation (FSF). To explore alternate licensing terms, contact
9 * the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
10 *
11 * The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GPL for more details. You should have
14 * received a copy of the GPL along with the OSKit; see the file COPYING. If
15 * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
16 */
17
18 #include "precomp.h"
19
20 int if_index = 0;
21 struct ifaddr **ifnet_addrs;
22
23 int ifqmaxlen = OSK_IFQ_MAXLEN;
24 struct ifnet *ifnet;
25
26 /*
27 * Network interface utility routines.
28 *
29 * Routines with ifa_ifwith* names take sockaddr *'s as
30 * parameters.
31 */
32
33 POSK_IFADDR TCPGetInterfaceData( PIP_INTERFACE IF ) {
34 NTSTATUS Status;
35 POSK_IFADDR ifaddr = IF->TCPContext;
36 struct sockaddr_in *addr_in;
37 struct sockaddr_in *dstaddr_in;
38 ASSERT(ifaddr);
39
40 ASSERT_LOCKED(&TCPLock);
41
42 RtlZeroMemory(ifaddr, sizeof(OSK_IFADDR) + 2 * sizeof( struct sockaddr_in ));
43
44 addr_in = (struct sockaddr_in *)&ifaddr[1];
45 dstaddr_in = (struct sockaddr_in *)&addr_in[1];
46
47 TI_DbgPrint(DEBUG_TCPIF,("Called\n"));
48
49 ifaddr->ifa_dstaddr = (struct sockaddr *)dstaddr_in;
50
51 /* XXX - Point-to-point interfaces not supported yet */
52 memset( &ifaddr->ifa_dstaddr, 0, sizeof( struct sockaddr ) );
53
54 ifaddr->ifa_addr = (struct sockaddr *)addr_in;
55 Status = GetInterfaceIPv4Address( IF,
56 ADE_UNICAST,
57 (PULONG)&addr_in->sin_addr.s_addr );
58
59 ASSERT(NT_SUCCESS(Status));
60
61 TI_DbgPrint(DEBUG_TCPIF,("interface %x : addr %x\n",
62 IF, addr_in->sin_addr.s_addr));
63
64 ifaddr->ifa_flags = 0; /* XXX what goes here? */
65 ifaddr->ifa_refcnt = 0; /* Anachronistic */
66 ifaddr->ifa_metric = 1; /* We can get it like in ninfo.c, if we want */
67 ifaddr->ifa_mtu = IF->MTU;
68
69 TI_DbgPrint(DEBUG_TCPIF,("Leaving\n"));
70
71 return ifaddr;
72 }
73
74 POSK_IFADDR TCPFindInterface( void *ClientData,
75 OSK_UINT AddrType,
76 OSK_UINT FindType,
77 OSK_SOCKADDR *ReqAddr,
78 OSK_IFADDR *Interface ) {
79 PIP_INTERFACE IF;
80 IP_ADDRESS Destination;
81 struct sockaddr_in *addr_in = (struct sockaddr_in *)ReqAddr;
82 POSK_IFADDR InterfaceData;
83
84 ASSERT_LOCKED(&TCPLock);
85
86 TI_DbgPrint(DEBUG_TCPIF,("called for type %d\n", FindType));
87
88 if( !ReqAddr ) {
89 TI_DbgPrint(DEBUG_TCPIF,("no addr or no ifaddr (%x)\n", ReqAddr));
90 return NULL;
91 }
92
93 Destination.Type = IP_ADDRESS_V4;
94 Destination.Address.IPv4Address = addr_in->sin_addr.s_addr;
95
96 TI_DbgPrint(DEBUG_TCPIF,("Address is %x\n", addr_in->sin_addr.s_addr));
97
98 IF = FindOnLinkInterface(&Destination);
99 if (!IF) return NULL;
100
101 InterfaceData = TCPGetInterfaceData(IF);
102
103 addr_in = (struct sockaddr_in *)
104 InterfaceData->ifa_addr;
105
106 TI_DbgPrint(DEBUG_TCPIF,("returning addr %x\n", addr_in->sin_addr.s_addr));
107
108 return InterfaceData;
109 }
110