📄 rom400_sock.h
字号:
/*---------------------------------------------------------------------------
* Copyright (C) 2003-2004 Dallas Semiconductor Corporation, All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Dallas Semiconductor
* shall not be used except as stated in the Dallas Semiconductor
* Branding Policy.
* ---------------------------------------------------------------------------
*
* This file contains function definitions for the built-in ROM functions
* of the Dallas Semiconductor 400 processor. This file is intended for use
* with the Keil MicroVision (uVision) C compiler.
*
* ---------------------------------------------------------------------------
*/
#ifndef __rom400_sock_
#define __rom400_sock_
#include <stdlib.h>
/** \file rom400_sock.h
* \brief Socket functions in the DS80C400 ROM
*
* This library contains functions for TCP, UDP and Multicast sockets,
* as well as network configuration. The functions in
* this library <b>are</b> safe to be called from multiple processes at
* the same time, with the exception of the function <i>#ping</i>.
* Both the traditional Berkeley style socket API and the
* <i>synchronized</i> socket functions are supported (the Berkeley style
* API is supported through macros implemented by the synchronized functions).
*
* It is recommended that new applications use the Berkeley style API
* for portability.
*
* Note that in order to run at 100 Mbs, the DS80C400 must be running at
* least 25MHz. This can be accomplished on the TINIm400 module by enabling
* the clock doubler.
*
* For detailed information on the DS80C400 please see the
* <a href="http://pdfserv.maxim-ic.com/arpdf/Design/DS80C400UG.pdf">
* High-Speed Microcontroller User's Guide: DS80C400 Supplement</a>.
*/
/** Version number associated with this header file. Should be the same as
* the version number returned by the <i>#syn_version</i> function.
* \sa #syn_version */
#define ROM400_SOCK_SYNCH_VERSION 9
/** Version number associated with this header file. Should be the same as
* the version number returned by the <i>#sock_version</i> function.
* \sa #sock_version */
#define ROM400_SOCK_VERSION 9
/** Argument to function <i>#socket</i> to create a UDP socket (same as <i>#SOCK_DGRAM</i>)
* \sa #socket */
#define SOCKET_TYPE_DATAGRAM 0
/** Argument to function <i>#socket</i> to create a TCP socket (same as <i>#SOCK_STREAM</i>)
* \sa #socket */
#define SOCKET_TYPE_STREAM 1
/** Argument to function <i>#socket</i> to create a UDP socket (same as <i>#SOCKET_TYPE_DATAGRAM</i>)
* \sa #socket */
#define SOCK_DGRAM 0
/** Argument to function <i>#socket</i> to create a TCP socket (same as <i>#SOCKET_TYPE_STREAM</i>)
* \sa #socket */
#define SOCK_STREAM 1
/** IPv4 protocol family define */
#define PF_INET 4
/** IPv4 family define, ignored by DS80C400 Silicon Software, but included for compatibility */
#define AF_INET 4
/** IPv6 family define, ignored by DS80C400 Silicon Software, but included for compatibility */
#define AF_INET6 6
/** Protocol ID define, ignored by DS80C400 Silicon Software, but included for compatibility */
#define IPPROTO_UDP 0
/** Argument for socket option. Enables/disables Nagle algorithm.
* \sa #getsockopt
* \sa #setsockopt */
#define TCP_NODELAY 0
/** Argument for socket option. Ignored by DS80C400 ROM.
* \sa #getsockopt
* \sa #setsockopt */
#define SO_LINGER 1
/** Argument for socket option. Socket inactivity timeout.
* \sa #getsockopt
* \sa #setsockopt */
#define SO_TIMEOUT 2
/** Argument for socket option. Local binding address.
* \sa #getsockopt
* \sa #setsockopt */
#define SO_BINDADDR 3
/** Flag for analyzing ethernet status.
* \sa #getethernetstatus */
#define ETH_STATUS_LINK 1
/**
* Structure for an IP address. For a normal, IPv4 (4 byte) address,
* set the address in sin_addr[12,13,14,15], with the most significant
* byte at sin_addr[12]. Notice the 3 byte <i>bogus_ptr</i> to deal with
* the TNI native interface overhead.
*
*/
struct sockaddr
{
unsigned char bogus_ptr[3]; ///< Overhead for TNI native interface.
unsigned char sin_addr[16]; ///< IP address. IPv4 address is in sin_addr[12-15] with MSB at sin_addr[12].
unsigned int sin_port; ///< 16 bit port number for the socket.
unsigned char sin_family; ///< Ignored by DS80C400 implementation.
};
/**
* Structure representing a 4 byte IPv4 address, for use with the
* #sockaddr_in structure.
*
*/
struct in_addr
{
unsigned long s_addr; ///< Address as an unsigned long (32 bits).
};
/**
* Structure representing a 16 byte IPv6 address.
*
*/
struct in6_addr
{
unsigned char s6_addr[16]; ///< IPv6 compatible address
};
/**
* Alternate structure for an IP address. For a normal, IPv4 (4 byte) address,
* set the address in sin_addr.s_addr, and set sin_zero to all 0's. Notice the
* 3 byte <i>bogus_ptr</i> to deal with the TNI native interface overhead.
*
*/
struct sockaddr_in
{
unsigned char bogus_ptr[3]; ///< Overhead for TNI native interface.
unsigned char sin_zero[12]; ///< Zeroes in IP address due to IPv6 support.
struct in_addr sin_addr; ///< IPv4 address structure.
unsigned int sin_port; ///< 16 bit port number for the socket.
unsigned char sin_family; ///< Ignored by DS80C400 implementation.
};
/**
* \brief Converts a numeric address to a string
*
* Converts a numeric IP address to a presentable format as a
* null terminated string. IPv4 addresses are formatted such as
* in "192.0.1.1". IPv6 addresses are formatted such as in
* "b803:8a11:0000:2121:fec5:0601:aa01:0102". Note that the '::'
* shortcut is <b>not</b> supported--a '0000' must be fully
* specified.
*
* \param family AF_INET or AF_INET6
* \param addr pointer to numeric representation of IP address
* \param strptr storage location for presentation string
* \param len size of storage area for strptr
*
* \return Reference to strptr, or NULL if the <i>family</i> is not recognized
* or if there is not enough space as declared by <i>len</i>
*
* \sa #inet_pton
*/
//---------------------------------------------------------------------------
char* inet_ntop(int family, void* addr, char* strptr, size_t len);
/**
* \brief Converts a string to a numeric IP address
*
* Converts a string represenation of an IP address into numeric format.
* IPv4 addresses are expected to be input in a format such as
* in "192.0.1.1". IPv6 addresses are expected to be formatted such
* as in "b8:03:8a:11:00:00:21:21:fe:c5:06:01:aa:01:01:02".
*
* \param family AF_INET or AF_INET6
* \param str address string to translate
* \param addr pointer to storage for numeric representation of IP address
*
* \return 1 for successful translation. 0 if the format was invalid, or
* the <i>family</i> was not recognized.
*
* \sa #inet_ntop
*/
//---------------------------------------------------------------------------
unsigned int inet_pton(int family, char* str, void* addr);
/**
* \brief Convert a number to network byte order
*
* Converts a word from host byte order to network byte order.
* On the DS80C400, the orders are the same, so this function
* does not alter the input data. This function is included
* for compatibility.
*
* \param x Input data to convert to network byte order
*
* \return Input data converted to network byte order
*/
//---------------------------------------------------------------------------
#define htons(x) (x)
/**
* \brief Convert a number to host byte order
*
* Converts a word from network byte order to host byte order.
* On the DS80C400, the orders are the same, so this function
* does not alter the input data. This function is included
* for compatibility.
*
* \param x Input data to convert to network byte order
*
* \return Input data converted to network byte order
*/
//---------------------------------------------------------------------------
#define ntohs(x) (x)
/**
* \brief Converts a string representing an IPv4 address to numeric form.
*
* Converts the input string into an IPv4 address suitable for setting
* in a <i>#sockaddr_in</i> structure.
*
* \param inet_string IPv4 address in string form
*
* \return Numberic IPv4 address
*
* \sa #sockaddr_in
*/
//---------------------------------------------------------------------------
unsigned long inet_addr(char* inet_string);
/**
* \brief Create a network socket for TCP or UDP communication.
*
* Creates a socket for network communication. This function returns
* a socket handle, but has not specific local address assigned to it.
* Note that this function calls <i>#task_gettaskid</i> through the
* function redirect table.
*
* \param type #SOCKET_TYPE_DATAGRAM or #SOCK_DGRAM for UDP,
* #SOCKET_TYPE_STREAM or #SOCK_STREAM for TCP
*
* \return -1 for failure, or the socket handle (socket number)
*
* \sa #bind
* \sa #connect
* \sa #closesocket
*/
//---------------------------------------------------------------------------
int syn_socket(unsigned int type);
/**
* \brief Closes a specific socket.
*
* Closes the specified socket that was created using the <i>socket</i>
* function.
*
* \param socket_num the socket handle to close
*
* \return 0 for success, non-zero for failure.
*
* \sa #socket
*/
//---------------------------------------------------------------------------
int syn_closesocket(int socket_num);
/**
* \brief Set the IP address parameter for future datagram calls.
*
* In order to keep the functions in this library multi-process-safe,
* datagram functions <i>#syn_sendto</i> and <i>#syn_recvfrom</i> cannot have
* as many parameters as their traditional counterparts. This function
* sets the pointer to the address structure that will be used as the address
* parameter for functions <i>#syn_sendto</i> and <i>#syn_recvfrom</i>.
*
* Note that the Berkeley style API is now supported and is multi-process
* safe.
*
* \param socket_num Socket number to set address for
* \param sending Set to 0 if this is an address for receiving,
* Set to 1 if this is an address for sending
* \param addr Address structure that will be used in future calls
* to <i>#syn_sendto</i> or <i>#syn_recvfrom</i>.
*
* \return socket_num (for Macro purposes)
*
* \sa #syn_sendto
* \sa #syn_recvfrom
*
*/
//---------------------------------------------------------------------------
int syn_setDatagramAddress(int socket_num, unsigned char sending, struct sockaddr* addr);
/**
* \brief Sends a UDP datagram to an address earlier specified by
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -