2 * iphlpapi dll implementation -- Setting and storing route information
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.
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.
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.
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
25 #include "iphlpapi_private.h"
29 #include <sys/types.h>
30 #ifdef HAVE_NETINET_IN_H
31 # include <netinet/in.h>
33 #ifdef HAVE_ARPA_INET_H
34 # include <arpa/inet.h>
36 #ifdef HAVE_ARPA_NAMESER_H
37 # include <arpa/nameser.h>
48 #include "wine/debug.h"
50 #define IP_FORWARD_ADD 3
51 #define IP_FORWARD_DEL 2
53 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi
);
55 DWORD
createIpForwardEntry( PMIB_IPFORWARDROW pRoute
) {
57 NTSTATUS status
= openTcpFile( &tcpFile
);
58 TCP_REQUEST_SET_INFORMATION_EX_SAFELY_SIZED req
=
59 TCP_REQUEST_SET_INFORMATION_INIT
;
66 if( NT_SUCCESS(status
) ) {
67 status
= getNthIpEntity( tcpFile
, 0, &id
);
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
);
76 (IPRouteEntry
*)&req
.Req
.Buffer
[0];
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
;
93 status
= DeviceIoControl( tcpFile
,
94 IOCTL_TCP_SET_INFORMATION_EX
,
103 closeTcpFile( tcpFile
);
106 TRACE("Returning: %08x (IOCTL was %08x)\n", status
, IOCTL_TCP_SET_INFORMATION_EX
);
108 if( NT_SUCCESS(status
) )
114 DWORD
setIpForwardEntry( PMIB_IPFORWARDROW pRoute
) {
119 DWORD
deleteIpForwardEntry( PMIB_IPFORWARDROW pRoute
) {
121 NTSTATUS status
= openTcpFile( &tcpFile
);
122 TCP_REQUEST_SET_INFORMATION_EX_SAFELY_SIZED req
=
123 TCP_REQUEST_SET_INFORMATION_INIT
;
126 DWORD returnSize
= 0;
130 if( NT_SUCCESS(status
) ) {
131 status
= getNthIpEntity( tcpFile
, 0, &id
);
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
);
140 (IPRouteEntry
*)&req
.Req
.Buffer
[0];
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
;
157 status
= DeviceIoControl( tcpFile
,
158 IOCTL_TCP_SET_INFORMATION_EX
,
167 closeTcpFile( tcpFile
);
170 TRACE("Returning: %08x (IOCTL was %08x)\n", status
, IOCTL_TCP_SET_INFORMATION_EX
);
172 if( NT_SUCCESS(status
) )