reshuffling of dlls
[reactos.git] / reactos / dll / win32 / iphlpapi / route_reactos.c
1 /*
2 * iphlpapi dll implementation -- Setting and storing route information
3 *
4 * These are stubs for functions that set routing information on the target
5 * operating system. They are grouped here because their implementation will
6 * vary widely by operating system.
7 *
8 * Copyright (C) 2004 Art Yerkes
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include "config.h"
25 #include "iphlpapi_private.h"
26
27 #include <stdarg.h>
28 #include <stdlib.h>
29 #include <sys/types.h>
30 #ifdef HAVE_NETINET_IN_H
31 # include <netinet/in.h>
32 #endif
33 #ifdef HAVE_ARPA_INET_H
34 # include <arpa/inet.h>
35 #endif
36 #ifdef HAVE_ARPA_NAMESER_H
37 # include <arpa/nameser.h>
38 #endif
39 #ifdef HAVE_RESOLV_H
40 # include <resolv.h>
41 #endif
42
43 #include "windef.h"
44 #include "winbase.h"
45 #include "winreg.h"
46 #include "resinfo.h"
47 #include "iphlpapi.h"
48 #include "wine/debug.h"
49
50 #define IP_FORWARD_ADD 3
51 #define IP_FORWARD_DEL 2
52
53 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi);
54
55 DWORD createIpForwardEntry( PMIB_IPFORWARDROW pRoute ) {
56 HANDLE tcpFile = INVALID_HANDLE_VALUE;
57 NTSTATUS status = openTcpFile( &tcpFile );
58 TCP_REQUEST_SET_INFORMATION_EX_SAFELY_SIZED req =
59 TCP_REQUEST_SET_INFORMATION_INIT;
60 IPRouteEntry *rte;
61 TDIEntityID id;
62 DWORD returnSize = 0;
63
64 DPRINT("Called.\n");
65
66 if( NT_SUCCESS(status) )
67 status = getNthIpEntity( tcpFile, 0, &id );
68
69 if( NT_SUCCESS(status) ) {
70 req.Req.ID.toi_class = INFO_CLASS_PROTOCOL;
71 req.Req.ID.toi_type = INFO_TYPE_PROVIDER;
72 req.Req.ID.toi_id = IP_MIB_ROUTETABLE_ENTRY_ID;
73 req.Req.ID.toi_entity = id;
74 req.Req.BufferSize = sizeof(*rte);
75 rte =
76 (IPRouteEntry *)&req.Req.Buffer[0];
77
78 // dwForwardPolicy
79 // dwForwardNextHopAS
80 rte->ire_dest = pRoute->dwForwardDest;
81 rte->ire_mask = pRoute->dwForwardMask;
82 rte->ire_gw = pRoute->dwForwardNextHop;
83 rte->ire_index = pRoute->dwForwardIfIndex;
84 rte->ire_type = IP_FORWARD_ADD;
85 rte->ire_proto = pRoute->dwForwardProto;
86 rte->ire_age = pRoute->dwForwardAge;
87 rte->ire_metric1 = pRoute->dwForwardMetric1;
88 rte->ire_metric2 = pRoute->dwForwardMetric2;
89 rte->ire_metric3 = pRoute->dwForwardMetric3;
90 rte->ire_metric4 = pRoute->dwForwardMetric4;
91 rte->ire_metric5 = pRoute->dwForwardMetric5;
92
93 status = DeviceIoControl( tcpFile,
94 IOCTL_TCP_SET_INFORMATION_EX,
95 &req,
96 sizeof(req),
97 NULL,
98 0,
99 &returnSize,
100 NULL );
101 }
102
103 if( tcpFile != INVALID_HANDLE_VALUE )
104 closeTcpFile( tcpFile );
105
106 DPRINT("Returning: %08x (IOCTL was %08x)\n", status, IOCTL_TCP_SET_INFORMATION_EX);
107
108 if( NT_SUCCESS(status) )
109 return NO_ERROR;
110 else
111 return status;
112 }
113
114 DWORD setIpForwardEntry( PMIB_IPFORWARDROW pRoute ) {
115 FIXME(":stub\n");
116 return (DWORD) 0;
117 }
118
119 DWORD deleteIpForwardEntry( PMIB_IPFORWARDROW pRoute ) {
120 HANDLE tcpFile = INVALID_HANDLE_VALUE;
121 NTSTATUS status = openTcpFile( &tcpFile );
122 TCP_REQUEST_SET_INFORMATION_EX_SAFELY_SIZED req =
123 TCP_REQUEST_SET_INFORMATION_INIT;
124 IPRouteEntry *rte;
125 TDIEntityID id;
126 DWORD returnSize = 0;
127
128 DPRINT("Called.\n");
129
130 if( NT_SUCCESS(status) )
131 status = getNthIpEntity( tcpFile, 0, &id );
132
133 if( NT_SUCCESS(status) ) {
134 req.Req.ID.toi_class = INFO_CLASS_PROTOCOL;
135 req.Req.ID.toi_type = INFO_TYPE_PROVIDER;
136 req.Req.ID.toi_id = IP_MIB_ROUTETABLE_ENTRY_ID;
137 req.Req.ID.toi_entity = id;
138 req.Req.BufferSize = sizeof(*rte);
139 rte =
140 (IPRouteEntry *)&req.Req.Buffer[0];
141
142 // dwForwardPolicy
143 // dwForwardNextHopAS
144 rte->ire_dest = pRoute->dwForwardDest;
145 rte->ire_mask = INADDR_NONE;
146 rte->ire_gw = pRoute->dwForwardNextHop;
147 rte->ire_index = pRoute->dwForwardIfIndex;
148 rte->ire_type = IP_FORWARD_DEL;
149 rte->ire_proto = pRoute->dwForwardProto;
150 rte->ire_age = pRoute->dwForwardAge;
151 rte->ire_metric1 = pRoute->dwForwardMetric1;
152 rte->ire_metric2 = INADDR_NONE;
153 rte->ire_metric3 = INADDR_NONE;
154 rte->ire_metric4 = INADDR_NONE;
155 rte->ire_metric5 = INADDR_NONE;
156
157 status = DeviceIoControl( tcpFile,
158 IOCTL_TCP_SET_INFORMATION_EX,
159 &req,
160 sizeof(req),
161 NULL,
162 0,
163 &returnSize,
164 NULL );
165 }
166
167 if( tcpFile != INVALID_HANDLE_VALUE )
168 closeTcpFile( tcpFile );
169
170 DPRINT("Returning: %08x (IOCTL was %08x)\n", status, IOCTL_TCP_SET_INFORMATION_EX);
171
172 if( NT_SUCCESS(status) )
173 return NO_ERROR;
174 else
175 return status;
176 }