📄 net_bsd.c
字号:
/*
*********************************************************************************************************
* uC/TCP-IP
* The Embedded TCP/IP Suite
*
* (c) Copyright 2003-2006; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
*
* uC/TCP-IP is provided in source form for FREE evaluation, for educational
* use or peaceful research. If you plan on using uC/TCP-IP in a commercial
* product you need to contact Micrium to properly license its use in your
* product. We provide ALL the source code for your convenience and to help
* you experience uC/TCP-IP. The fact that the source code is provided does
* NOT mean that you can use it without paying a licensing fee.
*
* Knowledge of the source code may NOT be used to develop a similar product.
*
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* BSD 4.x LAYER
*
* Filename : net_bsd.c
* Version : V1.87
* Programmer(s) : ITJ
*********************************************************************************************************
* Notice(s) : (1) The Institute of Electrical and Electronics Engineers and The Open Group, have given
* us permission to reprint portions of their documentation. Portions of this text are
* reprinted and reproduced in electronic form from the IEEE Std 1003.1, 2004 Edition,
* Standard for Information Technology -- Portable Operating System Interface (POSIX),
* The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute
* of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any
* discrepancy between these versions and the original IEEE and The Open Group Standard,
* the original IEEE and The Open Group Standard is the referee document. The original
* Standard can be obtained online at http://www.opengroup.org/unix/online.html.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#define NET_BSD_MODULE
#include <net.h>
/*
*********************************************************************************************************
* MODULE
*
* Note(s) : (1) See 'net_bsd.h MODULE'.
*********************************************************************************************************
*/
#ifdef NET_BSD_MODULE_PRESENT
/*$PAGE*/
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/
/*$PAGE*/
/*
*********************************************************************************************************
* STANDARD BSD 4.x FUNCTIONS
*
* Note(s) : (1) BSD 4.x function definitions are required only for applications that call BSD 4.x functions.
*
* See 'net_bsd.h MODULE Note #1b3'
* & 'net_bsd.h STANDARD BSD 4.x FUNCTION PROTOTYPES Note #1'.
*********************************************************************************************************
*/
#if (NET_BSD_CFG_API_EN == DEF_ENABLED) /* See Note #1. */
/*
*********************************************************************************************************
* socket()
*
* Description : Create a socket.
*
* Argument(s) : protocol_family Socket protocol family (see 'net_sock.c Note #1a').
*
* sock_type Socket type (see 'net_sock.c Note #1b').
*
* protocol Socket protocol (see 'net_sock.c Note #1c').
*
* Return(s) : Socket descriptor/handle identifier, if NO errors.
*
* -1, otherwise.
*
* Caller(s) : Application.
*
* This function is a network protocol suite application interface (API) function & MAY be
* called by application function(s).
*
* Note(s) : none.
*********************************************************************************************************
*/
#ifdef NET_SOCK_MODULE_PRESENT
int socket (int protocol_family,
int sock_type,
int protocol)
{
int rtn_code;
NET_ERR err;
rtn_code = (int)NetSock_Open((CPU_INT16S) protocol_family,
(CPU_INT16S) sock_type,
(CPU_INT16S) protocol,
(NET_ERR *)&err);
return (rtn_code);
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* close()
*
* Description : Close a socket.
*
* Argument(s) : sock_id Socket descriptor/handle identifier of socket to close.
*
* Return(s) : 0, if NO errors.
*
* -1, otherwise.
*
* Caller(s) : Application.
*
* This function is a network protocol suite application interface (API) function & MAY be
* called by application function(s).
*
* Note(s) : (1) Once an application closes its socket, NO further operations on the socket are allowed
* & the application MUST NOT continue to access the socket.
*
* #### Continued access to the closed socket by the application layer will likely corrupt
* the network socket layer.
*********************************************************************************************************
*/
#ifdef NET_SOCK_MODULE_PRESENT
int close (int sock_id)
{
int rtn_code;
NET_ERR err;
rtn_code = (int)NetSock_Close((NET_SOCK_ID) sock_id,
(NET_ERR *)&err);
return (rtn_code);
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* bind()
*
* Description : Bind a socket to a local address.
*
* Argument(s) : sock_id Socket descriptor/handle identifier of socket to bind to a local address.
*
* paddr_local Pointer to socket address structure (see Note #1).
*
* addr_len Length of socket address structure (in octets).
*
* Return(s) : 0, if NO errors.
*
* -1, otherwise.
*
* Caller(s) : Application.
*
* This function is a network protocol suite application interface (API) function & MAY be
* called by application function(s).
*
* Note(s) : (1) (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'.
*********************************************************************************************************
*/
#ifdef NET_SOCK_MODULE_PRESENT
int bind ( int sock_id,
struct sockaddr *paddr_local,
int addr_len)
{
int rtn_code;
NET_ERR err;
rtn_code = (int)NetSock_Bind((NET_SOCK_ID ) sock_id,
(NET_SOCK_ADDR *) paddr_local,
(NET_SOCK_ADDR_LEN) addr_len,
(NET_ERR *)&err);
return (rtn_code);
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* connect()
*
* Description : Connect a socket to a remote server.
*
* Argument(s) : sock_id Socket descriptor/handle identifier of socket to connect.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -