Webserver+3d print

Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers nbns_common.h Source File

nbns_common.h

Go to the documentation of this file.
00001 /**
00002  * @file nbns_common.h
00003  * @brief Functions common to NBNS client and NBNS responder
00004  *
00005  * @section License
00006  *
00007  * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
00008  *
00009  * This file is part of CycloneTCP Open.
00010  *
00011  * This program is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU General Public License
00013  * as published by the Free Software Foundation; either version 2
00014  * of the License, or (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software Foundation,
00023  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00024  *
00025  * @author Oryx Embedded SARL (www.oryx-embedded.com)
00026  * @version 1.7.6
00027  **/
00028 
00029 #ifndef _NBNS_COMMON_H
00030 #define _NBNS_COMMON_H
00031 
00032 //Dependencies
00033 #include "core/net.h"
00034 #include "dns/dns_common.h"
00035 
00036 //Default TTL value for NBNS resource records
00037 #ifndef NBNS_DEFAULT_RESOURCE_RECORD_TTL
00038    #define NBNS_DEFAULT_RESOURCE_RECORD_TTL 120
00039 #elif (NBNS_DEFAULT_RESOURCE_RECORD_TTL < 1)
00040    #error NBNS_DEFAULT_RESOURCE_RECORD_TTL parameter is not valid
00041 #endif
00042 
00043 //NBNS port number
00044 #define NBNS_PORT 137
00045 
00046 //Macro definition
00047 #define NBNS_ENCODE_H(c) ('A' + (((c) >> 4) & 0x0F))
00048 #define NBNS_ENCODE_L(c) ('A' + ((c) & 0x0F))
00049 
00050 
00051 /**
00052  * @brief NBNS flags
00053  **/
00054 
00055 typedef enum
00056 {
00057    NBNS_ONT_BNODE = 0x0000,
00058    NBNS_ONT_PNODE = 0x2000,
00059    NBNS_ONT_MNODE = 0x4000,
00060    NBNS_G_UNIQUE  = 0x0000,
00061    NBNS_G_GROUP   = 0x8000
00062 }DnsFlags;
00063 
00064 
00065 //CodeWarrior or Win32 compiler?
00066 #if defined(__CWCC__) || defined(_WIN32)
00067    #pragma pack(push, 1)
00068 #endif
00069 
00070 
00071 /**
00072  * @brief NBNS message header
00073  **/
00074 
00075 typedef __start_packed struct
00076 {
00077    uint16_t id;         //0-1
00078 #ifdef _CPU_BIG_ENDIAN
00079    uint16_t qr : 1;     //2
00080    uint16_t opcode : 4;
00081    uint16_t aa : 1;
00082    uint16_t tc : 1;
00083    uint16_t rd : 1;
00084    uint16_t ra : 1;     //3
00085    uint16_t z : 2;
00086    uint16_t b : 1;
00087    uint16_t rcode : 4;
00088 #else
00089    uint16_t rd : 1;     //2
00090    uint16_t tc : 1;
00091    uint16_t aa : 1;
00092    uint16_t opcode : 4;
00093    uint16_t qr : 1;
00094    uint16_t rcode : 4;  //3
00095    uint16_t b : 1;
00096    uint16_t z : 2;
00097    uint16_t ra : 1;
00098 #endif
00099    uint16_t qdcount;    //4-5
00100    uint16_t ancount;    //6-7
00101    uint16_t nscount;    //8-9
00102    uint16_t arcount;    //10-11
00103    uint8_t questions[]; //12
00104 } __end_packed NbnsHeader;
00105 
00106 
00107 /**
00108  * @brief NBNS address entry
00109  **/
00110 
00111 typedef __start_packed struct
00112 {
00113    uint16_t flags;
00114    Ipv4Addr addr;
00115 } __end_packed NbnsAddrEntry;
00116 
00117 
00118 //CodeWarrior or Win32 compiler?
00119 #if defined(__CWCC__) || defined(_WIN32)
00120    #pragma pack(pop)
00121 #endif
00122 
00123 
00124 //NBNS related functions
00125 error_t nbnsInit(NetInterface *interface);
00126 
00127 void nbnsProcessMessage(NetInterface *interface, const IpPseudoHeader *pseudoHeader,
00128    const UdpHeader *udpHeader, const NetBuffer *buffer, size_t offset, void *params);
00129 
00130 size_t nbnsEncodeName(const char_t *src, uint8_t *dest);
00131 
00132 size_t nbnsParseName(const NbnsHeader *message,
00133    size_t length, size_t pos, char_t *dest);
00134 
00135 bool_t nbnsCompareName(const NbnsHeader *message,
00136    size_t length, size_t pos, const char_t *name);
00137 
00138 #endif
00139