Webserver+3d print
Diff: cyclone_tcp/core/ip.h
- Revision:
- 0:8918a71cdbe9
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cyclone_tcp/core/ip.h Sat Feb 04 18:15:49 2017 +0000 @@ -0,0 +1,118 @@ +/** + * @file ip.h + * @brief IPv4 and IPv6 common routines + * + * @section License + * + * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved. + * + * This file is part of CycloneTCP Open. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * @author Oryx Embedded SARL (www.oryx-embedded.com) + * @version 1.7.6 + **/ + +#ifndef _IP_H +#define _IP_H + +//Dependencies +#include "ipv4/ipv4.h" +#include "ipv6/ipv6.h" + + +/** + * @brief IP supported protocols + **/ + +typedef enum +{ + IP_PROTOCOL_TCP = 6, + IP_PROTOCOL_UDP = 17 +} IpProtocol; + + +/** + * @brief IP network address + **/ + +typedef struct +{ + size_t length; + union + { +#if (IPV4_SUPPORT == ENABLED) + Ipv4Addr ipv4Addr; +#endif +#if (IPV6_SUPPORT == ENABLED) + Ipv6Addr ipv6Addr; +#endif + }; +} IpAddr; + + +/** + * @brief IP pseudo header + **/ + +typedef struct +{ + size_t length; + union + { +#if (IPV4_SUPPORT == ENABLED) + Ipv4PseudoHeader ipv4Data; +#endif +#if (IPV6_SUPPORT == ENABLED) + Ipv6PseudoHeader ipv6Data; +#endif + uint8_t data[4]; + }; +} IpPseudoHeader; + + +//IP related constants +extern const IpAddr IP_ADDR_ANY; +extern const IpAddr IP_ADDR_UNSPECIFIED; + +//IP related functions +error_t ipSendDatagram(NetInterface *interface, IpPseudoHeader *pseudoHeader, + NetBuffer *buffer, size_t offset, uint8_t ttl); + +error_t ipSelectSourceAddr(NetInterface **interface, + const IpAddr *destAddr, IpAddr *srcAddr); + +uint16_t ipCalcChecksum(const void *data, size_t length); +uint16_t ipCalcChecksumEx(const NetBuffer *buffer, size_t offset, size_t length); + +uint16_t ipCalcUpperLayerChecksum(const void *pseudoHeader, + size_t pseudoHeaderLength, const void *data, size_t dataLength); + +uint16_t ipCalcUpperLayerChecksumEx(const void *pseudoHeader, + size_t pseudoHeaderLength, const NetBuffer *buffer, size_t offset, size_t length); + +NetBuffer *ipAllocBuffer(size_t length, size_t *offset); + +error_t ipJoinMulticastGroup(NetInterface *interface, const IpAddr *groupAddr); +error_t ipLeaveMulticastGroup(NetInterface *interface, const IpAddr *groupAddr); + +bool_t ipIsUnspecifiedAddr(const IpAddr *ipAddr); + +error_t ipStringToAddr(const char_t *str, IpAddr *ipAddr); +char_t *ipAddrToString(const IpAddr *ipAddr, char_t *str); + +#endif +