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_ROUTE_ENTRY req
=
59 TCP_REQUEST_SET_INFORMATION_INIT
;
66 if( NT_SUCCESS(status
) ) {
67 status
= getNthIpEntity( tcpFile
, pRoute
->dwForwardIfIndex
, &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_ARPTABLE_ENTRY_ID
;
73 req
.Req
.ID
.toi_entity
.tei_instance
= id
.tei_instance
;
74 req
.Req
.ID
.toi_entity
.tei_entity
= CL_NL_ENTITY
;
75 req
.Req
.BufferSize
= sizeof(*rte
);
77 (IPRouteEntry
*)&req
.Req
.Buffer
[0];
81 rte
->ire_dest
= pRoute
->dwForwardDest
;
82 rte
->ire_mask
= pRoute
->dwForwardMask
;
83 rte
->ire_gw
= pRoute
->dwForwardNextHop
;
84 rte
->ire_index
= pRoute
->dwForwardIfIndex
;
85 rte
->ire_type
= IP_FORWARD_ADD
;
86 rte
->ire_proto
= pRoute
->dwForwardProto
;
87 rte
->ire_age
= pRoute
->dwForwardAge
;
88 rte
->ire_metric1
= pRoute
->dwForwardMetric1
;
89 rte
->ire_metric2
= pRoute
->dwForwardMetric2
;
90 rte
->ire_metric3
= pRoute
->dwForwardMetric3
;
91 rte
->ire_metric4
= pRoute
->dwForwardMetric4
;
92 rte
->ire_metric5
= pRoute
->dwForwardMetric5
;
94 status
= DeviceIoControl( tcpFile
,
95 IOCTL_TCP_SET_INFORMATION_EX
,
104 closeTcpFile( tcpFile
);
107 TRACE("Returning: %08x (IOCTL was %08x)\n", status
, IOCTL_TCP_SET_INFORMATION_EX
);
109 if( NT_SUCCESS(status
) )
115 DWORD
setIpForwardEntry( PMIB_IPFORWARDROW pRoute
) {
120 DWORD
deleteIpForwardEntry( PMIB_IPFORWARDROW pRoute
) {
122 NTSTATUS status
= openTcpFile( &tcpFile
);
123 TCP_REQUEST_SET_INFORMATION_EX_ROUTE_ENTRY req
=
124 TCP_REQUEST_SET_INFORMATION_INIT
;
127 DWORD returnSize
= 0;
131 if( NT_SUCCESS(status
) ) {
132 status
= getNthIpEntity( tcpFile
, pRoute
->dwForwardIfIndex
, &id
);
134 if( NT_SUCCESS(status
) ) {
135 req
.Req
.ID
.toi_class
= INFO_CLASS_PROTOCOL
;
136 req
.Req
.ID
.toi_type
= INFO_TYPE_PROVIDER
;
137 req
.Req
.ID
.toi_id
= IP_MIB_ARPTABLE_ENTRY_ID
;
138 req
.Req
.ID
.toi_entity
.tei_instance
= id
.tei_instance
;
139 req
.Req
.ID
.toi_entity
.tei_entity
= CL_NL_ENTITY
;
140 req
.Req
.BufferSize
= sizeof(*rte
);
142 (IPRouteEntry
*)&req
.Req
.Buffer
[0];
145 // dwForwardNextHopAS
146 rte
->ire_dest
= pRoute
->dwForwardDest
;
147 rte
->ire_mask
= INADDR_NONE
;
148 rte
->ire_gw
= pRoute
->dwForwardNextHop
;
149 rte
->ire_index
= pRoute
->dwForwardIfIndex
;
150 rte
->ire_type
= IP_FORWARD_DEL
;
151 rte
->ire_proto
= pRoute
->dwForwardProto
;
152 rte
->ire_age
= pRoute
->dwForwardAge
;
153 rte
->ire_metric1
= pRoute
->dwForwardMetric1
;
154 rte
->ire_metric2
= INADDR_NONE
;
155 rte
->ire_metric3
= INADDR_NONE
;
156 rte
->ire_metric4
= INADDR_NONE
;
157 rte
->ire_metric5
= INADDR_NONE
;
159 status
= DeviceIoControl( tcpFile
,
160 IOCTL_TCP_SET_INFORMATION_EX
,
169 closeTcpFile( tcpFile
);
172 TRACE("Returning: %08x (IOCTL was %08x)\n", status
, IOCTL_TCP_SET_INFORMATION_EX
);
174 if( NT_SUCCESS(status
) )