The Pedigree Project 0.1
ip.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
43/*
44 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
45 * All rights reserved.
46 *
47 * Redistribution and use in source and binary forms, with or without modification,
48 * are permitted provided that the following conditions are met:
49 *
50 * 1. Redistributions of source code must retain the above copyright notice,
51 * this list of conditions and the following disclaimer.
52 * 2. Redistributions in binary form must reproduce the above copyright notice,
53 * this list of conditions and the following disclaimer in the documentation
54 * and/or other materials provided with the distribution.
55 * 3. The name of the author may not be used to endorse or promote products
56 * derived from this software without specific prior written permission.
57 *
58 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
59 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
60 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
61 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
62 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
63 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
64 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
65 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
66 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
67 * OF SUCH DAMAGE.
68 *
69 * This file is part of the lwIP TCP/IP stack.
70 *
71 * Author: Adam Dunkels <adam@sics.se>
72 *
73 */
74
75#include "lwip/opt.h"
76
77#if LWIP_IPV4 || LWIP_IPV6
78
79#include "lwip/ip_addr.h"
80#include "lwip/ip.h"
81
83struct ip_globals ip_data;
84
85#if LWIP_IPV4 && LWIP_IPV6
86
87const ip_addr_t ip_addr_any_type = IPADDR_ANY_TYPE_INIT;
88
98int
99ipaddr_aton(const char *cp, ip_addr_t *addr)
100{
101 if (cp != NULL) {
102 const char* c;
103 for (c = cp; *c != 0; c++) {
104 if (*c == ':') {
105 /* contains a colon: IPv6 address */
106 if (addr) {
107 IP_SET_TYPE_VAL(*addr, IPADDR_TYPE_V6);
108 }
109 return ip6addr_aton(cp, ip_2_ip6(addr));
110 } else if (*c == '.') {
111 /* contains a dot: IPv4 address */
112 break;
113 }
114 }
115 /* call ip4addr_aton as fallback or if IPv4 was found */
116 if (addr) {
117 IP_SET_TYPE_VAL(*addr, IPADDR_TYPE_V4);
118 }
119 return ip4addr_aton(cp, ip_2_ip4(addr));
120 }
121 return 0;
122}
123
129err_t
130ip_input(struct pbuf *p, struct netif *inp)
131{
132 if (p != NULL) {
133 if (IP_HDR_GET_VERSION(p->payload) == 6) {
134 return ip6_input(p, inp);
135 }
136 return ip4_input(p, inp);
137 }
138 return ERR_VAL;
139}
140
141#endif /* LWIP_IPV4 && LWIP_IPV6 */
142
143#endif /* LWIP_IPV4 || LWIP_IPV6 */
s8_t err_t
Definition err.h:76
@ ERR_VAL
Definition err.h:94
@ IPADDR_TYPE_V6
Definition ip_addr.h:77
@ IPADDR_TYPE_V4
Definition ip_addr.h:75
#define IP_HDR_GET_VERSION(ptr)
Definition prot/ip.h:68
Definition netif.h:244
Definition pbuf.h:161
void * payload
Definition pbuf.h:166