ReactOS  0.4.15-dev-5112-g22d8c0f
netifapi.c
Go to the documentation of this file.
1 
7 /*
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  * derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28  * OF SUCH DAMAGE.
29  *
30  * This file is part of the lwIP TCP/IP stack.
31  *
32  */
33 
34 #include "lwip/opt.h"
35 
36 #if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */
37 
38 #include "lwip/netifapi.h"
39 #include "lwip/tcpip.h"
40 
44 void
45 do_netifapi_netif_add(struct netifapi_msg_msg *msg)
46 {
47  if (!netif_add( msg->netif,
48  msg->msg.add.ipaddr,
49  msg->msg.add.netmask,
50  msg->msg.add.gw,
51  msg->msg.add.state,
52  msg->msg.add.init,
53  msg->msg.add.input)) {
54  msg->err = ERR_IF;
55  } else {
56  msg->err = ERR_OK;
57  }
59 }
60 
64 void
65 do_netifapi_netif_set_addr(struct netifapi_msg_msg *msg)
66 {
67  netif_set_addr( msg->netif,
68  msg->msg.add.ipaddr,
69  msg->msg.add.netmask,
70  msg->msg.add.gw);
71  msg->err = ERR_OK;
73 }
74 
79 void
80 do_netifapi_netif_common(struct netifapi_msg_msg *msg)
81 {
82  if (msg->msg.common.errtfunc != NULL) {
83  msg->err = msg->msg.common.errtfunc(msg->netif);
84  } else {
85  msg->err = ERR_OK;
86  msg->msg.common.voidfunc(msg->netif);
87  }
89 }
90 
97 err_t
98 netifapi_netif_add(struct netif *netif,
99  ip_addr_t *ipaddr,
100  ip_addr_t *netmask,
101  ip_addr_t *gw,
102  void *state,
105 {
106  struct netifapi_msg msg;
107  msg.function = do_netifapi_netif_add;
108  msg.msg.netif = netif;
109  msg.msg.msg.add.ipaddr = ipaddr;
110  msg.msg.msg.add.netmask = netmask;
111  msg.msg.msg.add.gw = gw;
112  msg.msg.msg.add.state = state;
113  msg.msg.msg.add.init = init;
114  msg.msg.msg.add.input = input;
116  return msg.msg.err;
117 }
118 
125 err_t
126 netifapi_netif_set_addr(struct netif *netif,
127  ip_addr_t *ipaddr,
128  ip_addr_t *netmask,
129  ip_addr_t *gw)
130 {
131  struct netifapi_msg msg;
132  msg.function = do_netifapi_netif_set_addr;
133  msg.msg.netif = netif;
134  msg.msg.msg.add.ipaddr = ipaddr;
135  msg.msg.msg.add.netmask = netmask;
136  msg.msg.msg.add.gw = gw;
138  return msg.msg.err;
139 }
140 
147 err_t
148 netifapi_netif_common(struct netif *netif, netifapi_void_fn voidfunc,
149  netifapi_errt_fn errtfunc)
150 {
151  struct netifapi_msg msg;
152  msg.function = do_netifapi_netif_common;
153  msg.msg.netif = netif;
154  msg.msg.msg.common.voidfunc = voidfunc;
155  msg.msg.msg.common.errtfunc = errtfunc;
157  return msg.msg.err;
158 }
159 
160 #endif /* LWIP_NETIF_API */
err_t(* netif_input_fn)(struct pbuf *p, struct netif *inp)
Definition: netif.h:109
typedefPACK_STRUCT_END struct ip_addr ip_addr_t
Definition: ip_addr.h:64
#define TCPIP_NETIFAPI_ACK(m)
Definition: tcpip.h:72
static int init
Definition: wintirpc.c:33
s8_t err_t
Definition: err.h:47
struct netif * netif_add(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input)
Definition: netif.c:139
#define ERR_OK
Definition: err.h:52
Definition: netif.h:136
err_t(* netif_init_fn)(struct netif *netif)
Definition: netif.h:102
static int state
Definition: maze.c:121
GLenum GLenum GLenum input
Definition: glext.h:9031
#define NULL
Definition: types.h:112
#define msg(x)
Definition: auth_time.c:54
#define ERR_IF
Definition: err.h:72
#define TCPIP_NETIFAPI(m)
Definition: tcpip.h:71
void netif_set_addr(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw)
Definition: netif.c:221