⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sockets.c

📁 embedded ethernet code for pic18F
💻 C
字号:
#include <p18cxxx.h>
#include "sockets.h"




SOCKETINFO socketInfo[NSOCKETS];

// this is the list of put function for the server sockets you expose
// the template is
//
// void function(unsigned int TCPPayloadLength,FLAGS *flagStatus,unsigned char *TCPPayloadData)
//
// the put function takes the data sent to a server socket by a client and then processes it
//
void put8088(unsigned int,FLAGS *,unsigned char *);
void put8089(unsigned int,FLAGS *,unsigned char *);
void putEcho(unsigned int,FLAGS *,unsigned char *);
//
// this is the list of get function for the server sockets you expose
// the template is
//
// unsigned int function(FLAGS *flagStatus,unsigned char *TCPPayloadData)
//
// the get function returns a populated TCP data region from the server, based on previous data from the client plus internal
// state, it returns the TCP payload length
//
unsigned int get8088(FLAGS *,unsigned char *);
unsigned int get8089(FLAGS *,unsigned char *);
unsigned int getEcho(FLAGS *,unsigned char *);
//
// each server socket corresponds to a C module which includes "sockets.h" and implements these two functions
//
//
//
// this function registers server sockets with the system
// add in your server socket put and get functions below in socketInfo[i].putData and socketInfo[i].getData

void initSocketInfo(void)
{
	unsigned char i;
	
	for(i=0;i<NSOCKETS;i++)
	{
		socketInfo[i].syn=0;
		socketInfo[i].est=0;
		socketInfo[i].fin=0;
	}
	
	socketInfo[0].port=8088;
	socketInfo[0].putData=put8088;
	socketInfo[0].getData=get8088;
	
	
	socketInfo[1].port=8089;
	socketInfo[1].putData=put8089;
	socketInfo[1].getData=get8089;
	
	
	socketInfo[2].port=7;
	socketInfo[2].putData=putEcho;
	socketInfo[2].getData=getEcho;
	
	
}

// utilities

unsigned int isFirstPacket(FLAGS *flags)
{
	return flags->syn;
}

unsigned int isFinalPacket(FLAGS *flags)
{
	return flags->fin;
}

void makeFinalPacket(FLAGS *flags)
{
	flags->fin=1;
}

void makeResetPacket(FLAGS *flags)
{
	flags->rst=1;
}

unsigned int isPushPacket(FLAGS *flags)
{
	return flags->push;
}

void makePushPacket(FLAGS *flags)
{
	flags->push=1;
}

	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -