📄 net_bsd.h
字号:
/*
*********************************************************************************************************
* uC/TCP-IP
* The Embedded TCP/IP Suite
*
* (c) Copyright 2003-2006; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
* Knowledge of the source code may not be used to write a similar
* product. This file may only be used in accordance with a license
* and should not be redistributed in any way.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* BSD 4.x LAYER
*
* Filename : net_bsd.h
* Version : V1.86
* Programmer(s) : ITJ
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*
* Note(s) : (1) BSD 4.x module is required for :
*
* (a) Network sockets
* (b) Applications that require BSD 4.x application interface (API) :
* (1) Macro's
* (2) Data Types
* (3) Functions
*
* See also 'net_sock.h Note #1'
* & 'net_cfg.h BSD 4.x LAYER CONFIGURATION'.
*
* (2) The following BSD-module-present configuration value MUST be pre-#define'd in 'net_cfg_net.h'
* PRIOR to all other network modules that require BSD 4.x Layer Configuration (see 'net_cfg_net.h
* BSD 4.x LAYER CONFIGURATION Note #2b') :
*
* NET_BSD_MODULE_PRESENT
*********************************************************************************************************
*/
#ifdef NET_BSD_MODULE_PRESENT /* See Note #2. */
/*
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*/
#ifdef NET_BSD_MODULE
#define NET_BSD_EXT
#else
#define NET_BSD_EXT extern
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
#define NET_BSD_ERR_NONE 0
#define NET_BSD_ERR_DFLT -1
#define NET_BSD_ADDR_LEN_MAX 14 /* Sizeof(sockaddr.addr). */
#define NET_BSD_ADDR_IP_NBR_OCTETS_UNUSED 8
#define NET_BSD_ASCII_LEN_MAX_ADDR_IP NET_ASCII_LEN_MAX_ADDR_IP
/*
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* NETWORK WORD ORDER - TO - CPU WORD ORDER
*
* Note(s) : (1) BSD 4.x macro's are required only for applications that call BSD 4.x macro's.
*
* See also 'MODULE Note #1b1'.
*
* (2) See also 'net_util.h NETWORK WORD ORDER - TO - CPU WORD ORDER'.
*********************************************************************************************************
*/
#if (NET_BSD_CFG_API_EN == DEF_ENABLED) /* See Note #1. */
#define ntohs(val) (NET_UTIL_NET_TO_HOST_16(val))
#define ntohl(val) (NET_UTIL_NET_TO_HOST_32(val))
#define htons(val) (NET_UTIL_HOST_TO_NET_16(val))
#define htonl(val) (NET_UTIL_HOST_TO_NET_32(val))
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* BSD 4.x SOCKET ADDRESS DATA TYPES
*
* Note(s) : (1) BSD 4.x data types are required only for applications that reference BSD 4.x data types.
*
* See also 'MODULE Note #1b2'.
*
* (2) (a) Socket address structure 'Family' member MUST be configured in host-order & MUST NOT
* be converted to/from network-order.
*
* (b) Socket address structure addresses MUST be configured/converted from host-order to
* network-order.
*
* See also 'net_sock.h NETWORK SOCKET ADDRESS DATA TYPES Note #2'.
*********************************************************************************************************
*/
#if (NET_BSD_CFG_API_EN == DEF_ENABLED) /* See Note #1. */
/* ----------------- SOCKADDR ----------------- */
struct sockaddr {
CPU_INT16U sa_family; /* Sock family (see Note #2a). */
CPU_CHAR sa_data[NET_BSD_ADDR_LEN_MAX]; /* Sock addr (see Note #2b). */
};
/* ----------- SOCK IPv4 PORT/ADDR ------------ */
typedef CPU_INT16U in_port_t;
typedef CPU_INT32U in_addr_t;
struct in_addr {
in_addr_t s_addr;
};
/* --------------- SOCKADDR_IN ---------------- */
struct sockaddr_in {
CPU_INT16U sin_family; /* AF_INET family (see Note #2a). */
CPU_INT16U sin_port; /* Port nbr (see Note #2b). */
struct in_addr sin_addr; /* IP addr (see Note #2b). */
CPU_CHAR sin_zero[NET_BSD_ADDR_IP_NBR_OCTETS_UNUSED]; /* Unused (MUST be zero). */
};
#endif
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*
* Note(s) : (1) BSD 4.x global variables are required only for applications that call BSD 4.x functions.
*
* See also 'MODULE Note #1b'
* & 'STANDARD BSD 4.x FUNCTION PROTOTYPES Note #1'.
*********************************************************************************************************
*/
#if (NET_BSD_CFG_API_EN == DEF_ENABLED) /* See Note #1. */
#ifdef NET_SOCK_MODULE_PRESENT
#if (NET_SOCK_CFG_FAMILY == NET_SOCK_FAMILY_IP_V4)
NET_BSD_EXT CPU_CHAR NetBSD_IP_to_Str_Array[NET_BSD_ASCII_LEN_MAX_ADDR_IP];
#endif
#endif
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* STANDARD BSD 4.x FUNCTION PROTOTYPES
*
* Note(s) : (1) BSD 4.x function prototypes are required only for applications that call BSD 4.x functions.
*
* See also 'MODULE Note #1b3'.
*
* (2) (a) ???? Declare socket address & message length parameters as 'signed' or 'unsigned' integers?
*
* (b) ???? Declare socket message pointer parameters as 'void' or 'char' pointers?
*********************************************************************************************************
*/
#if (NET_BSD_CFG_API_EN == DEF_ENABLED) /* See Note #1. */
/* ------------- SOCK ALLOC FNCTS ------------- */
int socket ( int protocol_family,
int sock_type,
int protocol);
int close ( int sock_id);
int shutdown ( int sock_id,
int type);
/* ------------- LOCAL CONN FCNTS ------------- */
int bind ( int sock_id,
struct sockaddr *paddr_local,
int addr_len);
/* ------------ CLIENT CONN FCNTS ------------- */
int connect ( int sock_id,
struct sockaddr *paddr_remote,
int addr_len);
/* ------------ SERVER CONN FCNTS ------------- */
int listen ( int sock_id,
int sock_q_size);
int accept ( int sock_id,
struct sockaddr *paddr_remote,
int *paddr_len);
/* ----------------- RX FNCTS ----------------- */
int recvfrom ( int sock_id,
void *pdata_buf,
int data_buf_len,
int flags,
struct sockaddr *paddr_remote,
int *paddr_len);
int recv ( int sock_id,
void *pdata_buf,
int data_buf_len,
int flags);
/* ----------------- TX FNCTS ----------------- */
int sendto ( int sock_id,
void *p_data,
int data_len,
int flags,
struct sockaddr *paddr_remote,
int addr_len);
int send ( int sock_id,
void *p_data,
int data_len,
int flags);
/* ---------------- CONV FCNTS ---------------- */
in_addr_t inet_addr( char *paddr);
char *inet_ntoa(struct in_addr addr);
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE END
*
* Note(s) : (1) See 'MODULE Note #1'.
*********************************************************************************************************
*/
#endif /* End of BSD module include (see Note #1). */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -