📄 net_bsd.h
字号:
#define NET_BSD_ERR_NONE 0 /* See Note #1a1. */
#define NET_BSD_ERR_DFLT -1 /* See Note #1ab. */
#define NET_BSD_RTN_CODE_CONN_CLOSED 0 /* See Note #1b. */
/*$PAGE*/
/*
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* BSD NETWORK WORD ORDER - TO - CPU WORD ORDER MACRO'S
*
* Description : Convert data values to & from network word order to host CPU word order.
*
* Argument(s) : val Data value to convert (see Note #2).
*
* Return(s) : Converted data value (see Note #2).
*
* Caller(s) : Application.
*
* These macro's are network protocol suite application interface (API) macro's & MAY be
* called by application function(s).
*
* 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) 'val' data value to convert & any variable to receive the returned conversion MUST
* start on appropriate CPU word-aligned addresses. This is required because most word-
* aligned processors are more efficient & may even REQUIRE that multi-octet words start
* on CPU word-aligned addresses.
*
* (a) For 16-bit word-aligned processors, this means that
*
* all 16- & 32-bit words MUST start on addresses that are multiples of 2 octets
*
* (b) For 32-bit word-aligned processors, this means that
*
* all 16-bit words MUST start on addresses that are multiples of 2 octets
* all 32-bit words MUST start on addresses that are multiples of 4 octets
*
* See also 'net_util.h NETWORK WORD ORDER - TO - CPU WORD ORDER MACRO'S Note #1'.
*********************************************************************************************************
*/
#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'.
*********************************************************************************************************
*/
#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 + -