Webserver+3d print
cyclone_tcp/netbios/nbns_common.h@0:8918a71cdbe9, 2017-02-04 (annotated)
- Committer:
- Sergunb
- Date:
- Sat Feb 04 18:15:49 2017 +0000
- Revision:
- 0:8918a71cdbe9
nothing else
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sergunb | 0:8918a71cdbe9 | 1 | /** |
Sergunb | 0:8918a71cdbe9 | 2 | * @file nbns_common.h |
Sergunb | 0:8918a71cdbe9 | 3 | * @brief Functions common to NBNS client and NBNS responder |
Sergunb | 0:8918a71cdbe9 | 4 | * |
Sergunb | 0:8918a71cdbe9 | 5 | * @section License |
Sergunb | 0:8918a71cdbe9 | 6 | * |
Sergunb | 0:8918a71cdbe9 | 7 | * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved. |
Sergunb | 0:8918a71cdbe9 | 8 | * |
Sergunb | 0:8918a71cdbe9 | 9 | * This file is part of CycloneTCP Open. |
Sergunb | 0:8918a71cdbe9 | 10 | * |
Sergunb | 0:8918a71cdbe9 | 11 | * This program is free software; you can redistribute it and/or |
Sergunb | 0:8918a71cdbe9 | 12 | * modify it under the terms of the GNU General Public License |
Sergunb | 0:8918a71cdbe9 | 13 | * as published by the Free Software Foundation; either version 2 |
Sergunb | 0:8918a71cdbe9 | 14 | * of the License, or (at your option) any later version. |
Sergunb | 0:8918a71cdbe9 | 15 | * |
Sergunb | 0:8918a71cdbe9 | 16 | * This program is distributed in the hope that it will be useful, |
Sergunb | 0:8918a71cdbe9 | 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Sergunb | 0:8918a71cdbe9 | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Sergunb | 0:8918a71cdbe9 | 19 | * GNU General Public License for more details. |
Sergunb | 0:8918a71cdbe9 | 20 | * |
Sergunb | 0:8918a71cdbe9 | 21 | * You should have received a copy of the GNU General Public License |
Sergunb | 0:8918a71cdbe9 | 22 | * along with this program; if not, write to the Free Software Foundation, |
Sergunb | 0:8918a71cdbe9 | 23 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
Sergunb | 0:8918a71cdbe9 | 24 | * |
Sergunb | 0:8918a71cdbe9 | 25 | * @author Oryx Embedded SARL (www.oryx-embedded.com) |
Sergunb | 0:8918a71cdbe9 | 26 | * @version 1.7.6 |
Sergunb | 0:8918a71cdbe9 | 27 | **/ |
Sergunb | 0:8918a71cdbe9 | 28 | |
Sergunb | 0:8918a71cdbe9 | 29 | #ifndef _NBNS_COMMON_H |
Sergunb | 0:8918a71cdbe9 | 30 | #define _NBNS_COMMON_H |
Sergunb | 0:8918a71cdbe9 | 31 | |
Sergunb | 0:8918a71cdbe9 | 32 | //Dependencies |
Sergunb | 0:8918a71cdbe9 | 33 | #include "core/net.h" |
Sergunb | 0:8918a71cdbe9 | 34 | #include "dns/dns_common.h" |
Sergunb | 0:8918a71cdbe9 | 35 | |
Sergunb | 0:8918a71cdbe9 | 36 | //Default TTL value for NBNS resource records |
Sergunb | 0:8918a71cdbe9 | 37 | #ifndef NBNS_DEFAULT_RESOURCE_RECORD_TTL |
Sergunb | 0:8918a71cdbe9 | 38 | #define NBNS_DEFAULT_RESOURCE_RECORD_TTL 120 |
Sergunb | 0:8918a71cdbe9 | 39 | #elif (NBNS_DEFAULT_RESOURCE_RECORD_TTL < 1) |
Sergunb | 0:8918a71cdbe9 | 40 | #error NBNS_DEFAULT_RESOURCE_RECORD_TTL parameter is not valid |
Sergunb | 0:8918a71cdbe9 | 41 | #endif |
Sergunb | 0:8918a71cdbe9 | 42 | |
Sergunb | 0:8918a71cdbe9 | 43 | //NBNS port number |
Sergunb | 0:8918a71cdbe9 | 44 | #define NBNS_PORT 137 |
Sergunb | 0:8918a71cdbe9 | 45 | |
Sergunb | 0:8918a71cdbe9 | 46 | //Macro definition |
Sergunb | 0:8918a71cdbe9 | 47 | #define NBNS_ENCODE_H(c) ('A' + (((c) >> 4) & 0x0F)) |
Sergunb | 0:8918a71cdbe9 | 48 | #define NBNS_ENCODE_L(c) ('A' + ((c) & 0x0F)) |
Sergunb | 0:8918a71cdbe9 | 49 | |
Sergunb | 0:8918a71cdbe9 | 50 | |
Sergunb | 0:8918a71cdbe9 | 51 | /** |
Sergunb | 0:8918a71cdbe9 | 52 | * @brief NBNS flags |
Sergunb | 0:8918a71cdbe9 | 53 | **/ |
Sergunb | 0:8918a71cdbe9 | 54 | |
Sergunb | 0:8918a71cdbe9 | 55 | typedef enum |
Sergunb | 0:8918a71cdbe9 | 56 | { |
Sergunb | 0:8918a71cdbe9 | 57 | NBNS_ONT_BNODE = 0x0000, |
Sergunb | 0:8918a71cdbe9 | 58 | NBNS_ONT_PNODE = 0x2000, |
Sergunb | 0:8918a71cdbe9 | 59 | NBNS_ONT_MNODE = 0x4000, |
Sergunb | 0:8918a71cdbe9 | 60 | NBNS_G_UNIQUE = 0x0000, |
Sergunb | 0:8918a71cdbe9 | 61 | NBNS_G_GROUP = 0x8000 |
Sergunb | 0:8918a71cdbe9 | 62 | }DnsFlags; |
Sergunb | 0:8918a71cdbe9 | 63 | |
Sergunb | 0:8918a71cdbe9 | 64 | |
Sergunb | 0:8918a71cdbe9 | 65 | //CodeWarrior or Win32 compiler? |
Sergunb | 0:8918a71cdbe9 | 66 | #if defined(__CWCC__) || defined(_WIN32) |
Sergunb | 0:8918a71cdbe9 | 67 | #pragma pack(push, 1) |
Sergunb | 0:8918a71cdbe9 | 68 | #endif |
Sergunb | 0:8918a71cdbe9 | 69 | |
Sergunb | 0:8918a71cdbe9 | 70 | |
Sergunb | 0:8918a71cdbe9 | 71 | /** |
Sergunb | 0:8918a71cdbe9 | 72 | * @brief NBNS message header |
Sergunb | 0:8918a71cdbe9 | 73 | **/ |
Sergunb | 0:8918a71cdbe9 | 74 | |
Sergunb | 0:8918a71cdbe9 | 75 | typedef __start_packed struct |
Sergunb | 0:8918a71cdbe9 | 76 | { |
Sergunb | 0:8918a71cdbe9 | 77 | uint16_t id; //0-1 |
Sergunb | 0:8918a71cdbe9 | 78 | #ifdef _CPU_BIG_ENDIAN |
Sergunb | 0:8918a71cdbe9 | 79 | uint16_t qr : 1; //2 |
Sergunb | 0:8918a71cdbe9 | 80 | uint16_t opcode : 4; |
Sergunb | 0:8918a71cdbe9 | 81 | uint16_t aa : 1; |
Sergunb | 0:8918a71cdbe9 | 82 | uint16_t tc : 1; |
Sergunb | 0:8918a71cdbe9 | 83 | uint16_t rd : 1; |
Sergunb | 0:8918a71cdbe9 | 84 | uint16_t ra : 1; //3 |
Sergunb | 0:8918a71cdbe9 | 85 | uint16_t z : 2; |
Sergunb | 0:8918a71cdbe9 | 86 | uint16_t b : 1; |
Sergunb | 0:8918a71cdbe9 | 87 | uint16_t rcode : 4; |
Sergunb | 0:8918a71cdbe9 | 88 | #else |
Sergunb | 0:8918a71cdbe9 | 89 | uint16_t rd : 1; //2 |
Sergunb | 0:8918a71cdbe9 | 90 | uint16_t tc : 1; |
Sergunb | 0:8918a71cdbe9 | 91 | uint16_t aa : 1; |
Sergunb | 0:8918a71cdbe9 | 92 | uint16_t opcode : 4; |
Sergunb | 0:8918a71cdbe9 | 93 | uint16_t qr : 1; |
Sergunb | 0:8918a71cdbe9 | 94 | uint16_t rcode : 4; //3 |
Sergunb | 0:8918a71cdbe9 | 95 | uint16_t b : 1; |
Sergunb | 0:8918a71cdbe9 | 96 | uint16_t z : 2; |
Sergunb | 0:8918a71cdbe9 | 97 | uint16_t ra : 1; |
Sergunb | 0:8918a71cdbe9 | 98 | #endif |
Sergunb | 0:8918a71cdbe9 | 99 | uint16_t qdcount; //4-5 |
Sergunb | 0:8918a71cdbe9 | 100 | uint16_t ancount; //6-7 |
Sergunb | 0:8918a71cdbe9 | 101 | uint16_t nscount; //8-9 |
Sergunb | 0:8918a71cdbe9 | 102 | uint16_t arcount; //10-11 |
Sergunb | 0:8918a71cdbe9 | 103 | uint8_t questions[]; //12 |
Sergunb | 0:8918a71cdbe9 | 104 | } __end_packed NbnsHeader; |
Sergunb | 0:8918a71cdbe9 | 105 | |
Sergunb | 0:8918a71cdbe9 | 106 | |
Sergunb | 0:8918a71cdbe9 | 107 | /** |
Sergunb | 0:8918a71cdbe9 | 108 | * @brief NBNS address entry |
Sergunb | 0:8918a71cdbe9 | 109 | **/ |
Sergunb | 0:8918a71cdbe9 | 110 | |
Sergunb | 0:8918a71cdbe9 | 111 | typedef __start_packed struct |
Sergunb | 0:8918a71cdbe9 | 112 | { |
Sergunb | 0:8918a71cdbe9 | 113 | uint16_t flags; |
Sergunb | 0:8918a71cdbe9 | 114 | Ipv4Addr addr; |
Sergunb | 0:8918a71cdbe9 | 115 | } __end_packed NbnsAddrEntry; |
Sergunb | 0:8918a71cdbe9 | 116 | |
Sergunb | 0:8918a71cdbe9 | 117 | |
Sergunb | 0:8918a71cdbe9 | 118 | //CodeWarrior or Win32 compiler? |
Sergunb | 0:8918a71cdbe9 | 119 | #if defined(__CWCC__) || defined(_WIN32) |
Sergunb | 0:8918a71cdbe9 | 120 | #pragma pack(pop) |
Sergunb | 0:8918a71cdbe9 | 121 | #endif |
Sergunb | 0:8918a71cdbe9 | 122 | |
Sergunb | 0:8918a71cdbe9 | 123 | |
Sergunb | 0:8918a71cdbe9 | 124 | //NBNS related functions |
Sergunb | 0:8918a71cdbe9 | 125 | error_t nbnsInit(NetInterface *interface); |
Sergunb | 0:8918a71cdbe9 | 126 | |
Sergunb | 0:8918a71cdbe9 | 127 | void nbnsProcessMessage(NetInterface *interface, const IpPseudoHeader *pseudoHeader, |
Sergunb | 0:8918a71cdbe9 | 128 | const UdpHeader *udpHeader, const NetBuffer *buffer, size_t offset, void *params); |
Sergunb | 0:8918a71cdbe9 | 129 | |
Sergunb | 0:8918a71cdbe9 | 130 | size_t nbnsEncodeName(const char_t *src, uint8_t *dest); |
Sergunb | 0:8918a71cdbe9 | 131 | |
Sergunb | 0:8918a71cdbe9 | 132 | size_t nbnsParseName(const NbnsHeader *message, |
Sergunb | 0:8918a71cdbe9 | 133 | size_t length, size_t pos, char_t *dest); |
Sergunb | 0:8918a71cdbe9 | 134 | |
Sergunb | 0:8918a71cdbe9 | 135 | bool_t nbnsCompareName(const NbnsHeader *message, |
Sergunb | 0:8918a71cdbe9 | 136 | size_t length, size_t pos, const char_t *name); |
Sergunb | 0:8918a71cdbe9 | 137 | |
Sergunb | 0:8918a71cdbe9 | 138 | #endif |
Sergunb | 0:8918a71cdbe9 | 139 |