netbios.c, ping.c, sntp.c: minor changes: add comments, add some parameters, some coding style...

This commit is contained in:
fbernon 2007-11-13 00:58:51 +00:00
parent 61d74ecaaf
commit 8105013eb0
3 changed files with 120 additions and 38 deletions

View File

@ -1,6 +1,40 @@
#include "netbios.h"
/**
* @file
* NetBIOS name service sample
*
*/
/*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
*/
#include "lwip/opt.h"
#if LWIP_UDP /* don't build if not configured for use in lwipopts.h */
#include "lwip/udp.h"
#include "lwip/netif.h"
@ -12,8 +46,6 @@
* detect duplicate names!
*/
#if LWIP_UDP
/** NetBIOS name of LWIP device */
#ifndef NETBIOS_LWIP_NAME
#define NETBIOS_LWIP_NAME "NETBIOSLWIPDEV"
@ -27,7 +59,7 @@
/** The Time-To-Live for NetBIOS name responds (in seconds)
* Default is 300000 seconds (3 days, 11 hours, 20 minutes) */
#define NETBIOS_TTL 300000
#define NETBIOS_NAME_TTL 300000
/** NetBIOS header flags */
#define NETB_HFLAG_RESPONSE 0x8000
@ -87,12 +119,20 @@ PACK_STRUCT_END
# include "arch/epstruct.h"
#endif
/* @todo: does this have to be packed, too? */
/** NetBIOS message */
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h"
#endif
PACK_STRUCT_BEGIN
struct netbios_resp
{
struct netbios_hdr resp_hdr;
struct netbios_name_hdr resp_name;
};
} PACK_STRUCT_STRUCT;
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h"
#endif
/** NetBIOS decoding name */
static int
@ -208,7 +248,7 @@ netbios_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *ad
/* if the packet is a NetBIOS name query question */
if (((ntohs(netbios_hdr->flags) & NETB_HFLAG_OPCODE) == NETB_HFLAG_OPCODE_NAME_QUERY) &&
((ntohs(netbios_hdr->flags) & NETB_HFLAG_RESPONSE) == 0) &&
(ntohs(netbios_hdr->questions) == 1)) {
(ntohs(netbios_hdr->questions) == 1)) {
/* decode the NetBIOS name */
netbios_name_decoding( netbios_name_hdr->encname, netbios_name, sizeof(netbios_name));
/* if the packet is for us */
@ -233,13 +273,13 @@ netbios_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *ad
/* prepare NetBIOS header datas */
memcpy( resp->resp_name.encname, netbios_name_hdr->encname, sizeof(netbios_name_hdr->encname));
resp->resp_name.nametype = netbios_name_hdr->nametype;
resp->resp_name.type = netbios_name_hdr->type;
resp->resp_name.class = netbios_name_hdr->class;
resp->resp_name.ttl = htonl(NETBIOS_TTL);
resp->resp_name.datalen = htons(sizeof(resp->resp_name.flags)+sizeof(resp->resp_name.addr));
resp->resp_name.flags = htons(NETB_NFLAG_NODETYPE_BNODE);
resp->resp_name.addr = netif_default->ip_addr.addr;
resp->resp_name.nametype = netbios_name_hdr->nametype;
resp->resp_name.type = netbios_name_hdr->type;
resp->resp_name.class = netbios_name_hdr->class;
resp->resp_name.ttl = htonl(NETBIOS_NAME_TTL);
resp->resp_name.datalen = htons(sizeof(resp->resp_name.flags)+sizeof(resp->resp_name.addr));
resp->resp_name.flags = htons(NETB_NFLAG_NODETYPE_BNODE);
resp->resp_name.addr = netif_default->ip_addr.addr;
/* send the NetBIOS response */
udp_sendto(upcb, q, addr, port);

View File

@ -40,7 +40,7 @@
#include "lwip/opt.h"
#if LWIP_RAW && LWIP_ICMP
#if LWIP_RAW && LWIP_ICMP /* don't build if not configured for use in lwipopts.h */
#include "lwip/mem.h"
#include "lwip/raw.h"

View File

@ -1,11 +1,43 @@
#include "sntp.h"
/**
* @file
* SNTP client module
*
*/
/*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
*/
/* lwIP core includes */
#include "lwip/opt.h"
#if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
#include "lwip/sys.h"
#include "lwip/sockets.h"
/* C runtime includes */
#include "time.h"
/** This is an example of a "SNTP" client (with socket API).
@ -15,29 +47,39 @@
*
*/
#if LWIP_SOCKET
/* SNTP server address as string in "dot format" - avoid to use DNS here */
#ifndef SNTP_SERVER_ADDRESS
#define SNTP_SERVER_ADDRESS "91.121.71.87" /* pool.ntp.org */
#endif
/* SNTP macro to change system time and/or the update the RTC clock */
#ifndef SNTP_SYSTEM_TIME
#define SNTP_SYSTEM_TIME(t)
#endif
/**
* SNTP_DEBUG: Enable debugging for SNTP.
*/
#ifndef SNTP_DEBUG
#define SNTP_DEBUG LWIP_DBG_ON
#define SNTP_DEBUG LWIP_DBG_ON
#endif
/** SNTP server port */
#ifndef SNTP_PORT
#define SNTP_PORT 123
#endif
/** SNTP server address as IPv4 address in "u32_t" format */
#ifndef SNTP_SERVER_ADDRESS
#define SNTP_SERVER_ADDRESS inet_addr("91.121.71.87") /* pool.ntp.org */
#endif
/** SNTP receive timeout - in milliseconds */
#ifndef SNTP_RECV_TIMEOUT
#define SNTP_RECV_TIMEOUT 3000
#endif
/** SNTP update delay - in milliseconds */
#ifndef SNTP_UPDATE_DELAY
#define SNTP_UPDATE_DELAY 60000
#endif
/** SNTP macro to change system time and/or the update the RTC clock */
#ifndef SNTP_SYSTEM_TIME
#define SNTP_SYSTEM_TIME(t)
#endif
/* SNTP protocol defines */
#define SNTP_PORT 123
#define SNTP_RECV_TIMEOUT 3000
#define SNTP_UPDATE_DELAY 60000
#define SNTP_MAX_DATA_LEN 48
#define SNTP_RCV_TIME_OFS 32
#define SNTP_LI_NO_WARNING 0x00
@ -60,7 +102,7 @@ sntp_process( time_t t)
SNTP_SYSTEM_TIME(t);
/* display local time from GMT time */
LWIP_DEBUGF( SNTP_DEBUG, ("sntp_process: %s\n", ctime(&t)));
LWIP_DEBUGF( SNTP_DEBUG, ("sntp_process: %s", ctime(&t)));
}
/**
@ -82,7 +124,7 @@ sntp_request()
time_t t;
/* initialize SNTP server address */
sntp_server_address = inet_addr(SNTP_SERVER_ADDRESS);
sntp_server_address = SNTP_SERVER_ADDRESS;
/* if we got a valid SNTP server address... */
if (sntp_server_address!=0) {
@ -156,9 +198,9 @@ sntp_thread(void *arg)
}
}
#endif /* LWIP_SOCKET */
void
sntp_init(void)
{ sys_thread_new("sntp_thread", sntp_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
}
#endif /* LWIP_SOCKET */