Hi,
I am new to nxp controllers.
I am using MCU X presso IDE and Frdmk64F board for development of application.
I need to write TCP/IP socket programs for server and client.
please suggest me if any example codes for server and client socket programming compatible to MCU X presso IDE?
Hi
Please refer to below link,
Regards
Daniel
Hi Daniel,
Thanks for your suggestion.
I gone through the same steps which is mentioned in above link:
I imported one of the example code from the MCU X Presso IDE under lwip examples , Example name : lwip_tcpecho.bm
I got drivers and files required for socket programming.
in the main i added the supported header files and modified the code based on the document steps:
but while compiling it is showing error for socket related macros and when i opened the socket.h file, all the defines are under one #define
#if LWIP_SOCKET, it is looking like this macro is not defined and definitions under this macro showing as undeclared..
How to fix this issue:
Consider the bellow main and socket.h codes..
please refer any of complete project which has complete folder structure with required drivers.
//The main file.c
/*
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*******************************************************************************
* Includes // TCP/IP server codes
******************************************************************************/
#include "lwip/opt.h"
#if LWIP_TCP
#include "tcpecho_raw.h"
#include "lwip/timeouts.h"
#include "lwip/init.h"
#include "lwip/api.h"
#include "lwip/tcpip.h"
#include "lwip/memp.h"
#include "lwip/tcp.h"
#include "lwip/udp.h"
#include "lwip/etharp.h"
#include "lwip/dhcp.h"
#include "lwip/sockets.h"
#include "lwip/netdb.h"
#include "netif/ethernet.h"
#include "enet_ethernetif.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"
#include "fsl_phy.h"
#include "fsl_phyksz8081.h"
#include "fsl_enet_mdio.h"
#include "fsl_device_registers.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/* IP address configuration. */
#define configIP_ADDR0 192
#define configIP_ADDR1 168
#define configIP_ADDR2 0
#define configIP_ADDR3 102
/* Netmask configuration. */
#define configNET_MASK0 255
#define configNET_MASK1 255
#define configNET_MASK2 255
#define configNET_MASK3 0
/* Gateway address configuration. */
#define configGW_ADDR0 192
#define configGW_ADDR1 168
#define configGW_ADDR2 0
#define configGW_ADDR3 100
/* MAC address configuration. */
#define configMAC_ADDR \
{ \
0x02, 0x12, 0x13, 0x10, 0x15, 0x11 \
}
/* Address of PHY interface. */
#define EXAMPLE_PHY_ADDRESS BOARD_ENET0_PHY_ADDRESS
/* MDIO operations. */
#define EXAMPLE_MDIO_OPS enet_ops
/* PHY operations. */
#define EXAMPLE_PHY_OPS phyksz8081_ops
/* ENET clock frequency. */
#define EXAMPLE_CLOCK_FREQ CLOCK_GetFreq(kCLOCK_CoreSysClk)
#ifndef EXAMPLE_NETIF_INIT_FN
/*! @brief Network interface initialization function. */
#define EXAMPLE_NETIF_INIT_FN ethernetif0_init
#endif /* EXAMPLE_NETIF_INIT_FN */
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
static mdio_handle_t mdioHandle = {.ops = &EXAMPLE_MDIO_OPS};
static phy_handle_t phyHandle = {.phyAddr = EXAMPLE_PHY_ADDRESS, .mdioHandle = &mdioHandle, .ops = &EXAMPLE_PHY_OPS};
/*******************************************************************************
* Code
******************************************************************************/
/*!
* @brief Interrupt service for SysTick timer.
*/
void SysTick_Handler(void)
{
time_isr();
}
/*!
* @brief Main function.
*/
int main(void)
{
struct netif netif;
ip4_addr_t netif_ipaddr, netif_netmask, netif_gw;
ethernetif_config_t enet_config = {
.phyHandle = &phyHandle,
.macAddress = configMAC_ADDR,
};
SYSMPU_Type *base = SYSMPU;
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
/* Disable SYSMPU. */
base->CESR &= ~SYSMPU_CESR_VLD_MASK;
mdioHandle.resource.csrClock_Hz = EXAMPLE_CLOCK_FREQ;
time_init();
/* Init */
tcpip_init( NULL, NULL ); // added
IP4_ADDR(&netif_ipaddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3);
IP4_ADDR(&netif_netmask, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3);
IP4_ADDR(&netif_gw, configGW_ADDR0, configGW_ADDR1, configGW_ADDR2, configGW_ADDR3);
lwip_init();
netif_add(&netif, &netif_ipaddr, &netif_netmask, &netif_gw, &enet_config, EXAMPLE_NETIF_INIT_FN, ethernet_input);
netif_set_default(&netif);
netif_set_up(&netif);
while (0 == netif_is_up(&netif)) // added
{
/* If we get stuck in this loop, we have to check the network interface
* registers and try to fix it */
// vTaskDelay(1000/portTICK_RATE_MS); // need to check
}
tcpecho_raw_init();
PRINTF("\r\n************************************************\r\n");
PRINTF(" TCP Echo example\r\n");
PRINTF("************************************************\r\n");
PRINTF(" IPv4 Address : %u.%u.%u.%u\r\n", ((u8_t *)&netif_ipaddr)[0], ((u8_t *)&netif_ipaddr)[1],
((u8_t *)&netif_ipaddr)[2], ((u8_t *)&netif_ipaddr)[3]);
PRINTF(" IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t *)&netif_netmask)[0], ((u8_t *)&netif_netmask)[1],
((u8_t *)&netif_netmask)[2], ((u8_t *)&netif_netmask)[3]);
PRINTF(" IPv4 Gateway : %u.%u.%u.%u\r\n", ((u8_t *)&netif_gw)[0], ((u8_t *)&netif_gw)[1],
((u8_t *)&netif_gw)[2], ((u8_t *)&netif_gw)[3]);
PRINTF("************************************************\r\n");
while (1)
{
/* Poll the driver, get any outstanding frames */
ethernetif_input(&netif);
sys_check_timeouts(); /* Handle all system timeouts for all core protocols */
}
}
#endif
//*******************************TCP_server_code******************//
static void vTCP_Server_Task(void *param)
{
/* Variables */
int ret, clientfd, nbytes;
struct sockaddr_in sLocalAddr, client_addr;
struct hostent *phe;
char *lhost, *pnum;
int addrlen = sizeof(client_addr);
/* ID Server */
int sControl;
/* Debug buffer */
static uint8_t data_buffer[200];
/* TCP Data buffer */
static uint8_t Recepcion_buffer[500];
for(;;)
{
/* Reset structure */
memset((char *)&sLocalAddr, 0, sizeof(sLocalAddr));
/* Fill structure */
sLocalAddr.sin_family = AF_INET;
// sLocalAddr.sin_len = sizeof(sLocalAddr);
sLocalAddr.sin_addr.s_addr = 0; //INADDR_ANY;
sLocalAddr.sin_port = ntohs(1236);// PP_HTONS(TCP_CUSTOM_PORT);
#if 0
server_addr.sin_family = AF_INET;
server_addr.sin_port = PP_HTONS(TCP_CUSTOM_PORT);
server_addr.sin_addr.s_addr = INADDR_ANY;
#endif
/* Get socket */
#if 0
sControl = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sControl == -1) {
for(;;);
}
#endif
/* Create a new socket. */
sControl = socket(AF_INET, SOCK_STREAM, 0);
LWIP_ASSERT("server_sock >= 0 ", server_sock >= 0);
/* Bind a socket */
ret = bind(sControl, (struct sockaddr *)&sLocalAddr, sizeof(sLocalAddr));
if (ret < 0)
{
/* Wrong case, close socket */
closesocket(sControl);
for(;;);
}
/* Listen */
ret = listen(sControl, TCP_DEFAULT_LISTEN_BACKLOG); // listen(server_sock, 0);
if ( ret != 0 )
{
/* Wrong case, close socket */
closesocket(sControl);//
for(;;);
}
/* Reception packets */
while (1)
{
//TSMART_UART_Send(&tsmart_uart3, "Waiting for new connection...\r\n", strlen("Waiting for new connection...\r\n"), 1000/portTICK_RATE_MS);
clientfd = accept(sControl, (struct sockaddr*)&client_addr, (socklen_t *)&addrlen);
if (clientfd > 0){
do{
memset(Recepcion_buffer, 0 , sizeof(Recepcion_buffer));
/* Receive bytes */
nbytes = recv(clientfd, Recepcion_buffer, 38, MSG_MORE);
if(nbytes != 0)
{
/* Send confrmation to remote tcp client */
send(clientfd, "OK\r\n", sizeof("OK\r\n")-1 , 0);/* it send one Extra byte (value = 0) */
/* Debug message */
// sprintf(data_buffer, "--> IP:%s Port:%d", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
// TSMART_UART_Send(&tsmart_uart3, data_buffer, sizeof(data_buffer), 1000/portTICK_RATE_MS);
// sprintf(data_buffer, " %d Bytes: ", nbytes);
// TSMART_UART_Send(&tsmart_uart3, data_buffer, strlen(data_buffer),1000/portTICK_RATE_MS);
/* Show information */
//TSMART_UART_Send(&tsmart_uart3, Recepcion_buffer, nbytes, 1000/portTICK_RATE_MS);
//TSMART_UART_Send(&tsmart_uart3, "\r\n", strlen("\r\n"),1000/portTICK_RATE_MS);
PRINTF("*****Received Data bytes*************\r\n");
PRINTF("%d",nbytes );
}
}while(nbytes != 0);
/* Close socket */
ret = closesocket(clientfd);
if (ret < 0){
for(;;);
}
}
}
}
}
Hi @Megha :
Please note that lwip can be used in two basic modes, mainloop mode (NO_SYS) or OS mode (there is an OS running on the target system). In mainloop mode, only raw API can be used. In OS mode, raw API and sequential APIs can be used.
If you are using socket API, please USE OS mode(lwip_tcpecho.freertos). not bare metal (lwip_tcpecho.bm).
Hi,
I used lwip_tcpecho_freetos example and modified main code for socket programming. it compiled the code without error but not able to make server and client communication and it is showing communication is time out.
please check if the network is reachable. ping from server to client or from client to server.
Hi,
Thanks for your reply.
i have one more doubt in client codes.
initialization and assignment of IP address , gateway and netmask is required for both server and client codes?
bellow function is needed for both server and client?
static void stack_init(void *arg)
{
static struct netif netif;
ip4_addr_t netif_ipaddr, netif_netmask, netif_gw;
ethernetif_config_t enet_config = {
.phyHandle = &phyHandle,
.macAddress = configMAC_ADDR,
};
LWIP_UNUSED_ARG(arg);
mdioHandle.resource.csrClock_Hz = EXAMPLE_CLOCK_FREQ;
IP4_ADDR(&netif_ipaddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3);
IP4_ADDR(&netif_netmask, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3);
IP4_ADDR(&netif_gw, configGW_ADDR0, configGW_ADDR1, configGW_ADDR2, configGW_ADDR3);
tcpip_init(NULL, NULL);
netifapi_netif_add(&netif, &netif_ipaddr, &netif_netmask, &netif_gw, &enet_config, EXAMPLE_NETIF_INIT_FN,
tcpip_input);
netifapi_netif_set_default(&netif);
netifapi_netif_set_up(&netif);
PRINTF("\r\n************************************************\r\n");
PRINTF(" TCP Echo example\r\n");
PRINTF("************************************************\r\n");
PRINTF(" IPv4 Address : %u.%u.%u.%u\r\n", ((u8_t *)&netif_ipaddr)[0], ((u8_t *)&netif_ipaddr)[1],
((u8_t *)&netif_ipaddr)[2], ((u8_t *)&netif_ipaddr)[3]);
PRINTF(" IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t *)&netif_netmask)[0], ((u8_t *)&netif_netmask)[1],
((u8_t *)&netif_netmask)[2], ((u8_t *)&netif_netmask)[3]);
PRINTF(" IPv4 Gateway : %u.%u.%u.%u\r\n", ((u8_t *)&netif_gw)[0], ((u8_t *)&netif_gw)[1],
((u8_t *)&netif_gw)[2], ((u8_t *)&netif_gw)[3]);
PRINTF("************************************************\r\n");
tcpecho_init();
vTaskDelete(NULL);
}
yes, both server and client should initialize the TCP/IP stack
Hi,
Thanks for your reply.
i wrote complete client program and called function in the main after vTaskStartScheduler(); but it is not entering into client function ( confirmed by giving one print at start of function):
as per my understanding, that will not come out from vTaskStartScheduler(); function till task calls vTaskEndScheduler ();
int main(void)
{
SYSMPU_Type *base = SYSMPU;
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
/* Disable SYSMPU. */
base->CESR &= ~SYSMPU_CESR_VLD_MASK;
/* Initialize lwIP from thread */
if (sys_thread_new("main", stack_init, NULL, INIT_THREAD_STACKSIZE, INIT_THREAD_PRIO) == NULL)
{
LWIP_ASSERT("main(): Task creation failed.", 0);
}
vTaskStartScheduler();
vTCP_Client_Task();
/* Will not get here unless a task calls vTaskEndScheduler ()*/
return 0;
}
#endif
// Function for TCP/IP client socket programming
static void vTCP_Client_Task(void)
{
int ret, nbytes;
struct sockaddr_in server_addr;
/* ID Client */
int CControl;
/* TCP Data buffer */
// static uint8_t Recepcion_buffer[500];
static uint8_t data_buffer[1000];
PRINTF("**************Entering to client***************\r\n");
/* Create a new socket. */
CControl = socket(AF_INET, SOCK_STREAM, 0);
LWIP_ASSERT("CControl >= 0 ", CControl >= 0);
if (CControl == -1)
{
/* Impossible get a socket */
PRINTF("***Impossible get a socket*********\r\n");
for(;;);
}
/* Reset structure */
memset((char *)&server_addr, 0, sizeof(server_addr));
/* Fill structure */
server_addr.sin_family = AF_INET;
// server_addr.sin_len = sizeof(sLocalAddr);
server_addr.sin_addr.s_addr = inet_addr(SERVER_IP);//0; //INADDR_ANY;
server_addr.sin_port = ntohs(1236);// PP_HTONS(TCP_CUSTOM_PORT);
/* Connect to remote TCP server */
ret = connect(CControl, (struct sockaddr *)&server_addr, sizeof(server_addr));
if (ret == -1)
{
/* Close socket */
closesocket(CControl);
/* Impossible connect to remote TCP server */
PRINTF("***Impossible connect to remote TCP server************\r\n");
for(;;);
}
/* Reset buffer */
memset(data_buffer, 0x00, sizeof(data_buffer));
PRINTF("Enter the Message:\n\r");
SCANF("%s",data_buffer );
nbytes = send(CControl, data_buffer, sizeof(data_buffer) / sizeof(data_buffer[0]), 0);
if(nbytes < 0)
{
PRINTF("***ERROR FOR SENDING DATA************\r\n");
}
/* Check answer */
do{
/* Reset buffer */
memset(data_buffer, 0x00, sizeof(data_buffer));
/* Read socket */
ret = read(CControl, data_buffer, 500);
/* Debug message */
PRINTF("Buffer data %s",data_buffer );
}while(ret != 0);
/* Close connection */
closesocket(CControl);
}
Where i need to call this client program to make communication with server?
Hi,
I got solution from MCU Xpresso FreeRtos user manual..
created task and added the function it is running fine, thanks for your support
Hi @Megha
LWIP_SOCKET should be defined in lwipopts.h, this file in under source folder
* LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
*/
#define LWIP_SOCKET 1
Regards
Daniel
Hi Daniel,
Thanks for your suggestion.
I gone through the same steps which is mentioned in above link:
I imported one of the example code from the MCU X Presso IDE under lwip examples , Example name : lwip_tcpecho.bm
I got drivers and files required for socket programming.
in the main i added the supported header files and modified the code based on the document steps:
but while compiling it is showing error for socket related macros and when i opened the socket.h file, all the defines are under one #define
#if LWIP_SOCKET, it is looking like this macro is not defined and definitions under this macro showing as undeclared..
How to fix this issue:
Consider the bellow main and socket.h codes..
please refer any of complete project which has complete folder structure with required drivers.
//The main file.c
/*
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*******************************************************************************
* Includes // TCP/IP server codes
******************************************************************************/
#include "lwip/opt.h"
#if LWIP_TCP
#include "tcpecho_raw.h"
#include "lwip/timeouts.h"
#include "lwip/init.h"
#include "lwip/api.h"
#include "lwip/tcpip.h"
#include "lwip/memp.h"
#include "lwip/tcp.h"
#include "lwip/udp.h"
#include "lwip/etharp.h"
#include "lwip/dhcp.h"
#include "lwip/sockets.h"
#include "lwip/netdb.h"
#include "netif/ethernet.h"
#include "enet_ethernetif.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"
#include "fsl_phy.h"
#include "fsl_phyksz8081.h"
#include "fsl_enet_mdio.h"
#include "fsl_device_registers.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/* IP address configuration. */
#define configIP_ADDR0 192
#define configIP_ADDR1 168
#define configIP_ADDR2 0
#define configIP_ADDR3 102
/* Netmask configuration. */
#define configNET_MASK0 255
#define configNET_MASK1 255
#define configNET_MASK2 255
#define configNET_MASK3 0
/* Gateway address configuration. */
#define configGW_ADDR0 192
#define configGW_ADDR1 168
#define configGW_ADDR2 0
#define configGW_ADDR3 100
/* MAC address configuration. */
#define configMAC_ADDR \
{ \
0x02, 0x12, 0x13, 0x10, 0x15, 0x11 \
}
/* Address of PHY interface. */
#define EXAMPLE_PHY_ADDRESS BOARD_ENET0_PHY_ADDRESS
/* MDIO operations. */
#define EXAMPLE_MDIO_OPS enet_ops
/* PHY operations. */
#define EXAMPLE_PHY_OPS phyksz8081_ops
/* ENET clock frequency. */
#define EXAMPLE_CLOCK_FREQ CLOCK_GetFreq(kCLOCK_CoreSysClk)
#ifndef EXAMPLE_NETIF_INIT_FN
/*! @brief Network interface initialization function. */
#define EXAMPLE_NETIF_INIT_FN ethernetif0_init
#endif /* EXAMPLE_NETIF_INIT_FN */
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
static mdio_handle_t mdioHandle = {.ops = &EXAMPLE_MDIO_OPS};
static phy_handle_t phyHandle = {.phyAddr = EXAMPLE_PHY_ADDRESS, .mdioHandle = &mdioHandle, .ops = &EXAMPLE_PHY_OPS};
/*******************************************************************************
* Code
******************************************************************************/
/*!
* @brief Interrupt service for SysTick timer.
*/
void SysTick_Handler(void)
{
time_isr();
}
/*!
* @brief Main function.
*/
int main(void)
{
struct netif netif;
ip4_addr_t netif_ipaddr, netif_netmask, netif_gw;
ethernetif_config_t enet_config = {
.phyHandle = &phyHandle,
.macAddress = configMAC_ADDR,
};
SYSMPU_Type *base = SYSMPU;
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
/* Disable SYSMPU. */
base->CESR &= ~SYSMPU_CESR_VLD_MASK;
mdioHandle.resource.csrClock_Hz = EXAMPLE_CLOCK_FREQ;
time_init();
/* Init */
tcpip_init( NULL, NULL ); // added
IP4_ADDR(&netif_ipaddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3);
IP4_ADDR(&netif_netmask, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3);
IP4_ADDR(&netif_gw, configGW_ADDR0, configGW_ADDR1, configGW_ADDR2, configGW_ADDR3);
lwip_init();
netif_add(&netif, &netif_ipaddr, &netif_netmask, &netif_gw, &enet_config, EXAMPLE_NETIF_INIT_FN, ethernet_input);
netif_set_default(&netif);
netif_set_up(&netif);
while (0 == netif_is_up(&netif)) // added
{
/* If we get stuck in this loop, we have to check the network interface
* registers and try to fix it */
// vTaskDelay(1000/portTICK_RATE_MS); // need to check
}
tcpecho_raw_init();
PRINTF("\r\n************************************************\r\n");
PRINTF(" TCP Echo example\r\n");
PRINTF("************************************************\r\n");
PRINTF(" IPv4 Address : %u.%u.%u.%u\r\n", ((u8_t *)&netif_ipaddr)[0], ((u8_t *)&netif_ipaddr)[1],
((u8_t *)&netif_ipaddr)[2], ((u8_t *)&netif_ipaddr)[3]);
PRINTF(" IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t *)&netif_netmask)[0], ((u8_t *)&netif_netmask)[1],
((u8_t *)&netif_netmask)[2], ((u8_t *)&netif_netmask)[3]);
PRINTF(" IPv4 Gateway : %u.%u.%u.%u\r\n", ((u8_t *)&netif_gw)[0], ((u8_t *)&netif_gw)[1],
((u8_t *)&netif_gw)[2], ((u8_t *)&netif_gw)[3]);
PRINTF("************************************************\r\n");
while (1)
{
/* Poll the driver, get any outstanding frames */
ethernetif_input(&netif);
sys_check_timeouts(); /* Handle all system timeouts for all core protocols */
}
}
#endif
//*******************************TCP_server_code******************//
static void vTCP_Server_Task(void *param)
{
/* Variables */
int ret, clientfd, nbytes;
struct sockaddr_in sLocalAddr, client_addr;
struct hostent *phe;
char *lhost, *pnum;
int addrlen = sizeof(client_addr);
/* ID Server */
int sControl;
/* Debug buffer */
static uint8_t data_buffer[200];
/* TCP Data buffer */
static uint8_t Recepcion_buffer[500];
for(;;)
{
/* Reset structure */
memset((char *)&sLocalAddr, 0, sizeof(sLocalAddr));
/* Fill structure */
sLocalAddr.sin_family = AF_INET;
// sLocalAddr.sin_len = sizeof(sLocalAddr);
sLocalAddr.sin_addr.s_addr = 0; //INADDR_ANY;
sLocalAddr.sin_port = ntohs(1236);// PP_HTONS(TCP_CUSTOM_PORT);
#if 0
server_addr.sin_family = AF_INET;
server_addr.sin_port = PP_HTONS(TCP_CUSTOM_PORT);
server_addr.sin_addr.s_addr = INADDR_ANY;
#endif
/* Get socket */
#if 0
sControl = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sControl == -1) {
for(;;);
}
#endif
/* Create a new socket. */
sControl = socket(AF_INET, SOCK_STREAM, 0);
LWIP_ASSERT("server_sock >= 0 ", server_sock >= 0);
/* Bind a socket */
ret = bind(sControl, (struct sockaddr *)&sLocalAddr, sizeof(sLocalAddr));
if (ret < 0)
{
/* Wrong case, close socket */
closesocket(sControl);
for(;;);
}
/* Listen */
ret = listen(sControl, TCP_DEFAULT_LISTEN_BACKLOG); // listen(server_sock, 0);
if ( ret != 0 )
{
/* Wrong case, close socket */
closesocket(sControl);//
for(;;);
}
/* Reception packets */
while (1)
{
//TSMART_UART_Send(&tsmart_uart3, "Waiting for new connection...\r\n", strlen("Waiting for new connection...\r\n"), 1000/portTICK_RATE_MS);
clientfd = accept(sControl, (struct sockaddr*)&client_addr, (socklen_t *)&addrlen);
if (clientfd > 0){
do{
memset(Recepcion_buffer, 0 , sizeof(Recepcion_buffer));
/* Receive bytes */
nbytes = recv(clientfd, Recepcion_buffer, 38, MSG_MORE);
if(nbytes != 0)
{
/* Send confrmation to remote tcp client */
send(clientfd, "OK\r\n", sizeof("OK\r\n")-1 , 0);/* it send one Extra byte (value = 0) */
/* Debug message */
// sprintf(data_buffer, "--> IP:%s Port:%d", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
// TSMART_UART_Send(&tsmart_uart3, data_buffer, sizeof(data_buffer), 1000/portTICK_RATE_MS);
// sprintf(data_buffer, " %d Bytes: ", nbytes);
// TSMART_UART_Send(&tsmart_uart3, data_buffer, strlen(data_buffer),1000/portTICK_RATE_MS);
/* Show information */
//TSMART_UART_Send(&tsmart_uart3, Recepcion_buffer, nbytes, 1000/portTICK_RATE_MS);
//TSMART_UART_Send(&tsmart_uart3, "\r\n", strlen("\r\n"),1000/portTICK_RATE_MS);
PRINTF("*****Received Data bytes*************\r\n");
PRINTF("%d",nbytes );
}
}while(nbytes != 0);
/* Close socket */
ret = closesocket(clientfd);
if (ret < 0){
for(;;);
}
}
}
}
}
//sockets.h
#ifndef LWIP_HDR_SOCKETS_H
#define LWIP_HDR_SOCKETS_H
#include "lwip/opt.h"
#if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
#if LWIP_SOCKET_EXTERNAL_HEADERS
#include LWIP_SOCKET_EXTERNAL_HEADER_SOCKETS_H
#else /* LWIP_SOCKET_EXTERNAL_HEADERS */
#include "lwip/ip_addr.h"
#include "lwip/netif.h"
#include "lwip/err.h"
#include "lwip/inet.h"
#include "lwip/errno.h"
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
/* sockaddr and pals include length fields */
#define LWIP_SOCKET_HAVE_SA_LEN 1
/* If your port already typedef's sa_family_t, define SA_FAMILY_T_DEFINED
to prevent this code from redefining it. */
#if !defined(sa_family_t) && !defined(SA_FAMILY_T_DEFINED)
typedef u8_t sa_family_t;
#endif
/* If your port already typedef's in_port_t, define IN_PORT_T_DEFINED
to prevent this code from redefining it. */
#if !defined(in_port_t) && !defined(IN_PORT_T_DEFINED)
typedef u16_t in_port_t;
#endif
#if LWIP_IPV4
/* members are in network byte order */
struct sockaddr_in {
u8_t sin_len;
sa_family_t sin_family;
in_port_t sin_port;
struct in_addr sin_addr;
#define SIN_ZERO_LEN 8
char sin_zero[SIN_ZERO_LEN];
};
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
struct sockaddr_in6 {
u8_t sin6_len; /* length of this structure */
sa_family_t sin6_family; /* AF_INET6 */
in_port_t sin6_port; /* Transport layer port # */
u32_t sin6_flowinfo; /* IPv6 flow information */
struct in6_addr sin6_addr; /* IPv6 address */
u32_t sin6_scope_id; /* Set of interfaces for scope */
};
#endif /* LWIP_IPV6 */
struct sockaddr {
u8_t sa_len;
sa_family_t sa_family;
char sa_data[14];
};
struct sockaddr_storage {
u8_t s2_len;
sa_family_t ss_family;
char s2_data1[2];
u32_t s2_data2[3];
#if LWIP_IPV6
u32_t s2_data3[3];
#endif /* LWIP_IPV6 */
};
/* If your port already typedef's socklen_t, define SOCKLEN_T_DEFINED
to prevent this code from redefining it. */
#if !defined(socklen_t) && !defined(SOCKLEN_T_DEFINED)
typedef u32_t socklen_t;
#endif
#if !defined IOV_MAX
#define IOV_MAX 0xFFFF
#elif IOV_MAX > 0xFFFF
#error "IOV_MAX larger than supported by LwIP"
#endif /* IOV_MAX */
#if !defined(iovec)
struct iovec {
void *iov_base;
size_t iov_len;
};
#endif
typedef int msg_iovlen_t;
struct msghdr {
void *msg_name;
socklen_t msg_namelen;
struct iovec *msg_iov;
msg_iovlen_t msg_iovlen;
void *msg_control;
socklen_t msg_controllen;
int msg_flags;
};
/* struct msghdr->msg_flags bit field values */
#define MSG_TRUNC 0x04
#define MSG_CTRUNC 0x08
/* RFC 3542, Section 20: Ancillary Data */
struct cmsghdr {
socklen_t cmsg_len; /* number of bytes, including header */
int cmsg_level; /* originating protocol */
int cmsg_type; /* protocol-specific type */
};
/* Data section follows header and possible padding, typically referred to as
unsigned char cmsg_data[]; */
/* cmsg header/data alignment. NOTE: we align to native word size (double word
size on 16-bit arch) so structures are not placed at an unaligned address.
16-bit arch needs double word to ensure 32-bit alignment because socklen_t
could be 32 bits. If we ever have cmsg data with a 64-bit variable, alignment
will need to increase long long */
#define ALIGN_H(size) (((size) + sizeof(long) - 1U) & ~(sizeof(long)-1U))
#define ALIGN_D(size) ALIGN_H(size)
#define CMSG_FIRSTHDR(mhdr) \
((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
(struct cmsghdr *)(mhdr)->msg_control : \
(struct cmsghdr *)NULL)
#define CMSG_NXTHDR(mhdr, cmsg) \
(((cmsg) == NULL) ? CMSG_FIRSTHDR(mhdr) : \
(((u8_t *)(cmsg) + ALIGN_H((cmsg)->cmsg_len) \
+ ALIGN_D(sizeof(struct cmsghdr)) > \
(u8_t *)((mhdr)->msg_control) + (mhdr)->msg_controllen) ? \
(struct cmsghdr *)NULL : \
(struct cmsghdr *)((void*)((u8_t *)(cmsg) + \
ALIGN_H((cmsg)->cmsg_len)))))
#define CMSG_DATA(cmsg) ((void*)((u8_t *)(cmsg) + \
ALIGN_D(sizeof(struct cmsghdr))))
#define CMSG_SPACE(length) (ALIGN_D(sizeof(struct cmsghdr)) + \
ALIGN_H(length))
#define CMSG_LEN(length) (ALIGN_D(sizeof(struct cmsghdr)) + \
length)
/* Set socket options argument */
#define IFNAMSIZ NETIF_NAMESIZE
struct ifreq {
char ifr_name[IFNAMSIZ]; /* Interface name */
};
/* Socket protocol types (TCP/UDP/RAW) */
#define SOCK_STREAM 1
#define SOCK_DGRAM 2
#define SOCK_RAW 3
/*
* Option flags per-socket. These must match the SOF_ flags in ip.h (checked in init.c)
*/
#define SO_REUSEADDR 0x0004 /* Allow local address reuse */
#define SO_KEEPALIVE 0x0008 /* keep connections alive */
#define SO_BROADCAST 0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
/*
* Additional options, not kept in so_options.
*/
#define SO_DEBUG 0x0001 /* Unimplemented: turn on debugging info recording */
#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
#define SO_DONTROUTE 0x0010 /* Unimplemented: just use interface addresses */
#define SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */
#define SO_LINGER 0x0080 /* linger on close if data present */
#define SO_DONTLINGER ((int)(~SO_LINGER))
#define SO_OOBINLINE 0x0100 /* Unimplemented: leave received OOB data in line */
#define SO_REUSEPORT 0x0200 /* Unimplemented: allow local address & port reuse */
#define SO_SNDBUF 0x1001 /* Unimplemented: send buffer size */
#define SO_RCVBUF 0x1002 /* receive buffer size */
#define SO_SNDLOWAT 0x1003 /* Unimplemented: send low-water mark */
#define SO_RCVLOWAT 0x1004 /* Unimplemented: receive low-water mark */
#define SO_SNDTIMEO 0x1005 /* send timeout */
#define SO_RCVTIMEO 0x1006 /* receive timeout */
#define SO_ERROR 0x1007 /* get error status and clear */
#define SO_TYPE 0x1008 /* get socket type */
#define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */
#define SO_NO_CHECK 0x100a /* don't create UDP checksum */
#define SO_BINDTODEVICE 0x100b /* bind to device */
/*
* Structure used for manipulating linger option.
*/
struct linger {
int l_onoff; /* option on/off */
int l_linger; /* linger time in seconds */
};
/*
* Level number for (get/set)sockopt() to apply to socket itself.
*/
#define SOL_SOCKET 0xfff /* options for socket level */
#define AF_UNSPEC 0
#define AF_INET 2
#if LWIP_IPV6
#define AF_INET6 10
#else /* LWIP_IPV6 */
#define AF_INET6 AF_UNSPEC
#endif /* LWIP_IPV6 */
#define PF_INET AF_INET
#define PF_INET6 AF_INET6
#define PF_UNSPEC AF_UNSPEC
#define IPPROTO_IP 0
#define IPPROTO_ICMP 1
#define IPPROTO_TCP 6
#define IPPROTO_UDP 17
#if LWIP_IPV6
#define IPPROTO_IPV6 41
#define IPPROTO_ICMPV6 58
#endif /* LWIP_IPV6 */
#define IPPROTO_UDPLITE 136
#define IPPROTO_RAW 255
/* Flags we can use with send and recv. */
#define MSG_PEEK 0x01 /* Peeks at an incoming message */
#define MSG_WAITALL 0x02 /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */
#define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */
#define MSG_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */
#define MSG_MORE 0x10 /* Sender will send more */
#define MSG_NOSIGNAL 0x20 /* Uninmplemented: Requests not to send the SIGPIPE signal if an attempt to send is made on a stream-oriented socket that is no longer connected. */
/*
* Options for level IPPROTO_IP
*/
#define IP_TOS 1
#define IP_TTL 2
#define IP_PKTINFO 8
#if LWIP_TCP
/*
* Options for level IPPROTO_TCP
*/
#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */
#define TCP_KEEPALIVE 0x02 /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */
#define TCP_KEEPIDLE 0x03 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */
#define TCP_KEEPINTVL 0x04 /* set pcb->keep_intvl - Use seconds for get/setsockopt */
#define TCP_KEEPCNT 0x05 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */
#define TCP_USER_TIMEOUT 0x12 /* set pcb->user_timeout - How long for loss retry before timeout */
#endif /* LWIP_TCP */
#if LWIP_IPV6
/*
* Options for level IPPROTO_IPV6
*/
#define IPV6_CHECKSUM 7 /* RFC3542: calculate and insert the ICMPv6 checksum for raw sockets. */
#define IPV6_V6ONLY 27 /* RFC3493: boolean control to restrict AF_INET6 sockets to IPv6 communications only. */
#endif /* LWIP_IPV6 */
#if LWIP_UDP && LWIP_UDPLITE
/*
* Options for level IPPROTO_UDPLITE
*/
#define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */
#define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */
#endif /* LWIP_UDP && LWIP_UDPLITE*/
#if LWIP_MULTICAST_TX_OPTIONS
/*
* Options and types for UDP multicast traffic handling
*/
#define IP_MULTICAST_TTL 5
#define IP_MULTICAST_IF 6
#define IP_MULTICAST_LOOP 7
#endif /* LWIP_MULTICAST_TX_OPTIONS */
#if LWIP_IGMP
/*
* Options and types related to multicast membership
*/
#define IP_ADD_MEMBERSHIP 3
#define IP_DROP_MEMBERSHIP 4
typedef struct ip_mreq {
struct in_addr imr_multiaddr; /* IP multicast address of group */
struct in_addr imr_interface; /* local IP address of interface */
} ip_mreq;
#endif /* LWIP_IGMP */
#if LWIP_IPV4
struct in_pktinfo {
unsigned int ipi_ifindex; /* Interface index */
struct in_addr ipi_addr; /* Destination (from header) address */
};
#endif /* LWIP_IPV4 */
#if LWIP_IPV6_MLD
/*
* Options and types related to IPv6 multicast membership
*/
#define IPV6_JOIN_GROUP 12
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
#define IPV6_LEAVE_GROUP 13
#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
typedef struct ipv6_mreq {
struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast addr */
unsigned int ipv6mr_interface; /* interface index, or 0 */
} ipv6_mreq;
#endif /* LWIP_IPV6_MLD */
/*
* The Type of Service provides an indication of the abstract
* parameters of the quality of service desired. These parameters are
* to be used to guide the selection of the actual service parameters
* when transmitting a datagram through a particular network. Several
* networks offer service precedence, which somehow treats high
* precedence traffic as more important than other traffic (generally
* by accepting only traffic above a certain precedence at time of high
* load). The major choice is a three way tradeoff between low-delay,
* high-reliability, and high-throughput.
* The use of the Delay, Throughput, and Reliability indications may
* increase the cost (in some sense) of the service. In many networks
* better performance for one of these parameters is coupled with worse
* performance on another. Except for very unusual cases at most two
* of these three indications should be set.
*/
#define IPTOS_TOS_MASK 0x1E
#define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
#define IPTOS_LOWDELAY 0x10
#define IPTOS_THROUGHPUT 0x08
#define IPTOS_RELIABILITY 0x04
#define IPTOS_LOWCOST 0x02
#define IPTOS_MINCOST IPTOS_LOWCOST
/*
* The Network Control precedence designation is intended to be used
* within a network only. The actual use and control of that
* designation is up to each network. The Internetwork Control
* designation is intended for use by gateway control originators only.
* If the actual use of these precedence designations is of concern to
* a particular network, it is the responsibility of that network to
* control the access to, and use of, those precedence designations.
*/
#define IPTOS_PREC_MASK 0xe0
#define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK)
#define IPTOS_PREC_NETCONTROL 0xe0
#define IPTOS_PREC_INTERNETCONTROL 0xc0
#define IPTOS_PREC_CRITIC_ECP 0xa0
#define IPTOS_PREC_FLASHOVERRIDE 0x80
#define IPTOS_PREC_FLASH 0x60
#define IPTOS_PREC_IMMEDIATE 0x40
#define IPTOS_PREC_PRIORITY 0x20
#define IPTOS_PREC_ROUTINE 0x00
/*
* Commands for ioctlsocket(), taken from the BSD file fcntl.h.
* lwip_ioctl only supports FIONREAD and FIONBIO, for now
*
* Ioctl's have the command encoded in the lower word,
* and the size of any in or out parameters in the upper
* word. The high 2 bits of the upper word are used
* to encode the in/out status of the parameter; for now
* we restrict parameters to at most 128 bytes.
*/
#if !defined(FIONREAD) || !defined(FIONBIO)
#define IOCPARM_MASK 0x7fUL /* parameters must be < 128 bytes */
#define IOC_VOID 0x20000000UL /* no parameters */
#define IOC_OUT 0x40000000UL /* copy out parameters */
#define IOC_IN 0x80000000UL /* copy in parameters */
#define IOC_INOUT (IOC_IN|IOC_OUT)
/* 0x20000000 distinguishes new &
old ioctl's */
#define _IO(x,y) ((long)(IOC_VOID|((x)<<8)|(y)))
#define _IOR(x,y,t) ((long)(IOC_OUT|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y)))
#define _IOW(x,y,t) ((long)(IOC_IN|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y)))
#endif /* !defined(FIONREAD) || !defined(FIONBIO) */
/* Get (not sent + not acked) data bytes in send buffer. */
#define SIOCOUTQ _IOR('s', 115, unsigned long)
#ifndef FIONREAD
#define FIONREAD _IOR('f', 127, unsigned long) /* get # bytes to read */
#endif
#ifndef FIONBIO
#define FIONBIO _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */
#endif
/* Socket I/O Controls: unimplemented */
#ifndef SIOCSHIWAT
#define SIOCSHIWAT _IOW('s', 0, unsigned long) /* set high watermark */
#define SIOCGHIWAT _IOR('s', 1, unsigned long) /* get high watermark */
#define SIOCSLOWAT _IOW('s', 2, unsigned long) /* set low watermark */
#define SIOCGLOWAT _IOR('s', 3, unsigned long) /* get low watermark */
#define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */
#endif
/* commands for fnctl */
#ifndef F_GETFL
#define F_GETFL 3
#endif
#ifndef F_SETFL
#define F_SETFL 4
#endif
/* File status flags and file access modes for fnctl,
these are bits in an int. */
#ifndef O_NONBLOCK
#define O_NONBLOCK 1 /* nonblocking I/O */
#endif
#ifndef O_NDELAY
#define O_NDELAY O_NONBLOCK /* same as O_NONBLOCK, for compatibility */
#endif
#ifndef O_RDONLY
#define O_RDONLY 2
#endif
#ifndef O_WRONLY
#define O_WRONLY 4
#endif
#ifndef O_RDWR
#define O_RDWR (O_RDONLY|O_WRONLY)
#endif
#ifndef SHUT_RD
#define SHUT_RD 0
#define SHUT_WR 1
#define SHUT_RDWR 2
#endif
/* FD_SET used for lwip_select */
#ifndef FD_SET
#undef FD_SETSIZE
/* Make FD_SETSIZE match NUM_SOCKETS in socket.c */
#define FD_SETSIZE MEMP_NUM_NETCONN
#define LWIP_SELECT_MAXNFDS (FD_SETSIZE + LWIP_SOCKET_OFFSET)
#define FDSETSAFESET(n, code) do { \
if (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0)) { \
code; }} while(0)
#define FDSETSAFEGET(n, code) (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0) ?\
(code) : 0)
#define FD_SET(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] = (u8_t)((p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] | (1 << (((n)-LWIP_SOCKET_OFFSET) & 7))))
#define FD_CLR(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] = (u8_t)((p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] & ~(1 << (((n)-LWIP_SOCKET_OFFSET) & 7))))
#define FD_ISSET(n,p) FDSETSAFEGET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] & (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p)))
typedef struct fd_set
{
unsigned char fd_bits [(FD_SETSIZE+7)/8];
} fd_set;
#elif FD_SETSIZE < (LWIP_SOCKET_OFFSET + MEMP_NUM_NETCONN)
#error "external FD_SETSIZE too small for number of sockets"
#else
#define LWIP_SELECT_MAXNFDS FD_SETSIZE
#endif /* FD_SET */
/* poll-related defines and types */
/* @todo: find a better way to guard the definition of these defines and types if already defined */
#if !defined(POLLIN) && !defined(POLLOUT)
#define POLLIN 0x1
#define POLLOUT 0x2
#define POLLERR 0x4
#define POLLNVAL 0x8
/* Below values are unimplemented */
#define POLLRDNORM 0x10
#define POLLRDBAND 0x20
#define POLLPRI 0x40
#define POLLWRNORM 0x80
#define POLLWRBAND 0x100
#define POLLHUP 0x200
typedef unsigned int nfds_t;
struct pollfd
{
int fd;
short events;
short revents;
};
#endif
/** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided
* by your system, set this to 0 and include <sys/time.h> in cc.h */
#ifndef LWIP_TIMEVAL_PRIVATE
#define LWIP_TIMEVAL_PRIVATE 1
#endif
#if LWIP_TIMEVAL_PRIVATE
struct timeval {
long tv_sec; /* seconds */
long tv_usec; /* and microseconds */
};
#endif /* LWIP_TIMEVAL_PRIVATE */
#ifdef __cplusplus
}
#endif
#endif /* LWIP_SOCKET_EXTERNAL_HEADERS */
#ifdef __cplusplus
extern "C" {
#endif
#define lwip_socket_init() /* Compatibility define, no init needed. */
void lwip_socket_thread_init(void); /* LWIP_NETCONN_SEM_PER_THREAD==1: initialize thread-local semaphore */
void lwip_socket_thread_cleanup(void); /* LWIP_NETCONN_SEM_PER_THREAD==1: destroy thread-local semaphore */
#if LWIP_COMPAT_SOCKETS == 2
/* This helps code parsers/code completion by not having the COMPAT functions as defines */
#define lwip_accept accept
#define lwip_bind bind
#define lwip_shutdown shutdown
#define lwip_getpeername getpeername
#define lwip_getsockname getsockname
#define lwip_setsockopt setsockopt
#define lwip_getsockopt getsockopt
#define lwip_close closesocket
#define lwip_connect connect
#define lwip_listen listen
#define lwip_recv recv
#define lwip_recvmsg recvmsg
#define lwip_recvfrom recvfrom
#define lwip_send send
#define lwip_sendmsg sendmsg
#define lwip_sendto sendto
#define lwip_socket socket
#if LWIP_SOCKET_SELECT
#define lwip_select select
#endif
#if LWIP_SOCKET_POLL
#define lwip_poll poll
#endif
#define lwip_ioctl ioctlsocket
#define lwip_inet_ntop inet_ntop
#define lwip_inet_pton inet_pton
#if LWIP_POSIX_SOCKETS_IO_NAMES
#define lwip_read read
#define lwip_readv readv
#define lwip_write write
#define lwip_writev writev
#undef lwip_close
#define lwip_close close
#define closesocket(s) close(s)
int fcntl(int s, int cmd, ...);
#undef lwip_ioctl
#define lwip_ioctl ioctl
#define ioctlsocket ioctl
#endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
#endif /* LWIP_COMPAT_SOCKETS == 2 */
int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen);
int lwip_shutdown(int s, int how);
int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen);
int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen);
int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen);
int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen);
int lwip_close(int s);
int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen);
int lwip_listen(int s, int backlog);
ssize_t lwip_recv(int s, void *mem, size_t len, int flags);
ssize_t lwip_read(int s, void *mem, size_t len);
ssize_t lwip_readv(int s, const struct iovec *iov, int iovcnt);
ssize_t lwip_recvfrom(int s, void *mem, size_t len, int flags,
struct sockaddr *from, socklen_t *fromlen);
ssize_t lwip_recvmsg(int s, struct msghdr *message, int flags);
ssize_t lwip_send(int s, const void *dataptr, size_t size, int flags);
ssize_t lwip_sendmsg(int s, const struct msghdr *message, int flags);
ssize_t lwip_sendto(int s, const void *dataptr, size_t size, int flags,
const struct sockaddr *to, socklen_t tolen);
int lwip_socket(int domain, int type, int protocol);
ssize_t lwip_write(int s, const void *dataptr, size_t size);
ssize_t lwip_writev(int s, const struct iovec *iov, int iovcnt);
#if LWIP_SOCKET_SELECT
int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
struct timeval *timeout);
#endif
#if LWIP_SOCKET_POLL
int lwip_poll(struct pollfd *fds, nfds_t nfds, int timeout);
#endif
int lwip_ioctl(int s, long cmd, void *argp);
int lwip_fcntl(int s, int cmd, int val);
const char *lwip_inet_ntop(int af, const void *src, char *dst, socklen_t size);
int lwip_inet_pton(int af, const char *src, void *dst);
#if LWIP_COMPAT_SOCKETS
#if LWIP_COMPAT_SOCKETS != 2
/** @ingroup socket */
#define accept(s,addr,addrlen) lwip_accept(s,addr,addrlen)
/** @ingroup socket */
#define bind(s,name,namelen) lwip_bind(s,name,namelen)
/** @ingroup socket */
#define shutdown(s,how) lwip_shutdown(s,how)
/** @ingroup socket */
#define getpeername(s,name,namelen) lwip_getpeername(s,name,namelen)
/** @ingroup socket */
#define getsockname(s,name,namelen) lwip_getsockname(s,name,namelen)
/** @ingroup socket */
#define setsockopt(s,level,optname,opval,optlen) lwip_setsockopt(s,level,optname,opval,optlen)
/** @ingroup socket */
#define getsockopt(s,level,optname,opval,optlen) lwip_getsockopt(s,level,optname,opval,optlen)
/** @ingroup socket */
#define closesocket(s) lwip_close(s)
/** @ingroup socket */
#define connect(s,name,namelen) lwip_connect(s,name,namelen)
/** @ingroup socket */
#define listen(s,backlog) lwip_listen(s,backlog)
/** @ingroup socket */
#define recv(s,mem,len,flags) lwip_recv(s,mem,len,flags)
/** @ingroup socket */
#define recvmsg(s,message,flags) lwip_recvmsg(s,message,flags)
/** @ingroup socket */
#define recvfrom(s,mem,len,flags,from,fromlen) lwip_recvfrom(s,mem,len,flags,from,fromlen)
/** @ingroup socket */
#define send(s,dataptr,size,flags) lwip_send(s,dataptr,size,flags)
/** @ingroup socket */
#define sendmsg(s,message,flags) lwip_sendmsg(s,message,flags)
/** @ingroup socket */
#define sendto(s,dataptr,size,flags,to,tolen) lwip_sendto(s,dataptr,size,flags,to,tolen)
/** @ingroup socket */
#define socket(domain,type,protocol) lwip_socket(domain,type,protocol)
#if LWIP_SOCKET_SELECT
/** @ingroup socket */
#define select(maxfdp1,readset,writeset,exceptset,timeout) lwip_select(maxfdp1,readset,writeset,exceptset,timeout)
#endif
#if LWIP_SOCKET_POLL
/** @ingroup socket */
#define poll(fds,nfds,timeout) lwip_poll(fds,nfds,timeout)
#endif
/** @ingroup socket */
#define ioctlsocket(s,cmd,argp) lwip_ioctl(s,cmd,argp)
/** @ingroup socket */
#define inet_ntop(af,src,dst,size) lwip_inet_ntop(af,src,dst,size)
/** @ingroup socket */
#define inet_pton(af,src,dst) lwip_inet_pton(af,src,dst)
#if LWIP_POSIX_SOCKETS_IO_NAMES
/** @ingroup socket */
#define read(s,mem,len) lwip_read(s,mem,len)
/** @ingroup socket */
#define readv(s,iov,iovcnt) lwip_readv(s,iov,iovcnt)
/** @ingroup socket */
#define write(s,dataptr,len) lwip_write(s,dataptr,len)
/** @ingroup socket */
#define writev(s,iov,iovcnt) lwip_writev(s,iov,iovcnt)
/** @ingroup socket */
#define close(s) lwip_close(s)
/** @ingroup socket */
#define fcntl(s,cmd,val) lwip_fcntl(s,cmd,val)
/** @ingroup socket */
#define ioctl(s,cmd,argp) lwip_ioctl(s,cmd,argp)
#endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
#endif /* LWIP_COMPAT_SOCKETS != 2 */
#endif /* LWIP_COMPAT_SOCKETS */
#ifdef __cplusplus
}
#endif
#endif /* LWIP_SOCKET */
#endif /* LWIP_HDR_SOCKETS_H */
Hi Daniel,
Please can you help me to fix the issue related to supported files needed for socket programming?
Please consider my above post