libif.c1
来自「世纪民生公司的cs6209的开发ftp服务器的演示源程序。」· C1 代码 · 共 114 行
C1
114 行
/*
Note : Don't remove or rename any function or variable if you work with
MYSON libreary.
*/
#define LIBIF_C
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "hpserver.h"
#include "620xenet.h"
#include "timer.h"
#include "ether.h"
#include "netutil.h"
#include "net.h"
#include "ip.h"
#include "tcp.h"
#include "config.h"
#include "ftp.h"
GENFRAME genframe; /* Frame for network Tx/Rx */
NODE locnode; /* My Ethernet and IP addresses */
/* Return ptr to local node 'n' (n=0 for first), return 0 if doesn't exist
** Used by IP functions to get my netmask & gateway addresses */
NODE *locnode_n(int n)
{
return(n==0 ? &locnode : 0);
}
/* Upcall from TCP stack to server when opening, connecting, receiving data
** or closing. Return 0 to prevent connection opening, or close if connected
Note: Don't remove or rename this function if you work with MYSON libreary.*/
int server_action(TSOCK *ts, CONN_STATE conn)
{
WORD port;
ts->connflags =ts->connflags|TURGE|TPUSH; //Enable this line will set the Urgent and Push Flag in TCP/IP packet.
port = ts->loc.port;
/* printf("\nconnect from:%1bu.%1bu.%1bu.%1bu port:%d to port:%d",
(unsigned char)((long)ts->rem.ip>>24),
(unsigned char)((long)ts->rem.ip>>16),
(unsigned char)((long)ts->rem.ip>>8),
(unsigned char)((long)ts->rem.ip),
((unsigned int)ts->rem.port),
((unsigned int)ts->loc.port));
*/
if (port==80){
// place code for HTTP server
}
else if (port==23){
// place code for TELNET server
}
return 0;
}
/* Upcall from TCP stack to client when opening, connecting, receiving data
** or closing. Return 0 to prevent connection opening, or close if connected
Note: Don't remove or rename this function if you work with MYSON libreary.*/
int client_action(TSOCK *ts, CONN_STATE conn)
{
ts->connflags =ts->connflags|TURGE|TPUSH; //Enable this line will set the Urgent and Push Flag in TCP/IP packet.
if (ts->upcall)
return (ts->upcall(ts,conn));
return 0; //client socket doesn't have upcall function.
}
/* Get a frame from the network, return length excl. hardware header */
int get_frame (GENFRAME xdata *gfp)
{
// check if anything is received on the Ethernet Interface
if (gfp->g.dtype == DTYPE_ETHER)
if ((gfp->g.len = Ethernet_Receive (gfp->buff))>0)
{
return (gfp->g.len - sizeof (ETHERHDR));
}
return (0);
}
extern xdata unsigned char nic_xmit_buf [];
/* Put frame out onto the network */
int put_frame (GENFRAME xdata *gfp, int len)
{
int ret=0;
if (len > 0)
{
// wait until the last transmission is done
while (!Ethernet_Transmit_Ready ());
// copy to a page-aligned buffer
memcpy (nic_xmit_buf, gfp->buff, (WORD)len);
ret = Ethernet_Transmit (nic_xmit_buf, (WORD)len);
}
return(ret);
}/* Receive a UDP datagram: return non-0 if client state-change */
int udp_receive(GENFRAME *gfp, int len)
{
return (0);
}
/******************/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?