📄 user.c
字号:
/* */
/*************************************************************************/
void netsetbroad(unsigned char *st)
{
memcpy ((void *)broadip, (const void *)st, 4);
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* netsetmask(unsigned char *) */
/* */
/* DESCRIPTION */
/* */
/* Set the network mask. */
/* */
/* CALLED BY */
/* parse_bootpacket */
/* Ssetgates */
/* ipinit */
/* */
/* CALLS */
/* */
/* */
/*************************************************************************/
void netsetmask(const uchar *st)
{
memcpy ((void *)nnmask, (const void *)st, 4);
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* netest(int16) */
/* */
/* DESCRIPTION */
/* */
/* Checks to see if a particular session has been established yet. */
/* Returns 0 if the connection is in "established" state. */
/* */
/* CALLED BY */
/* */
/* CALLS */
/* */
/* tcp_sendack */
/* Send_SYN_FIN */
/* */
/*************************************************************************/
int16 netest(int16 pn)
{
struct port *prt;
if(pn<0 || pn>NPORTS)
return(-2);
if(NU_NULL==(prt=portlist[pn]))
return(-2);
if(prt->state==SEST)
return(0);
else
if(prt->state==SCWAIT) {
if(!prt->in.contain) {
prt->tcpout.t.flags=TFIN | TACK;
Send_SYN_FIN(prt, 0);
prt->state=SLAST;
return(-1);
} /* end if */
else
return(0); /* still more data to be read */
} /* end if */
return(-1);
} /* end netest */
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* netlisten(uint16) */
/* */
/* DESCRIPTION */
/* */
/* Listen to a TCP port number and make the connection automatically */
/* when the SYN packet comes in. The TCP layer will notify the higher */
/* layers with a CONOPEN event. Save the port number returned to */
/* refer to this connection. */
/* */
/* example usage : portnum=netlisten ( service ) */
/* */
/* Returns<0 if error */
/* */
/* CALLED BY */
/* TCP_Interpret */
/* */
/* CALLS */
/* */
/* intswap */
/* makeport */
/* */
/*************************************************************************/
int16 netlisten(uint16 serv)
{
int16 pnum;
struct port *prt;
uint16 nn;
if((pnum=makeport())<0)
return(-2);
if(NU_NULL==(prt=portlist[pnum]))
return(-2);
prt->in.port=serv;
prt->out.port=0; /* accept any outside port #*/
prt->in.lasttime=n_clicks(); /* set time we started */
prt->state = SLISTEN;
prt->credit = WINDOWSIZE; /* default value until changed */
prt->tcpout.i.protocol = PROTTCP;
prt->tcpout.t.source=intswap(serv); /* set service here too */
/*
* install maximum segment size which will be sent out in the first
* ACK-SYN packet
*/
prt->tcpout.x.options[0]=2;
prt->tcpout.x.options[1]=4;
/* install maximum segment size */
nn=intswap((uint16)nnsegsize);
memcpy ((void *)&prt->tcpout.x.options[2], (const void *)&nn, 2);
return(pnum);
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* netxopen(uint8 *, uint16, uint16, uint16, uint16, uint16) */
/* */
/* DESCRIPTION */
/* */
/* Open a network socket for the user to *machine* using */
/* port *service*. The rest of the parameters are self-explanatory. */
/* */
/* CALLED BY */
/* Snetopen */
/* */
/* CALLS */
/* */
/* makeport */
/* netdlayer */
/* */
/* HISTORY */
/* */
/* Maiqi Qian 12/05/96 Fixed the problem of SOR0229 */
/* 1. Move makeport() and related lines after netdlayer successed. */
/* 2. Move assignment of SSYNS to port->state to doconnectl() after */
/* Send_SYN_FIN(). */
/* */
/*************************************************************************/
int16 netxopen (uint8 *machine, uint16 service, uint16 rto,
uint16 mtu, uint16 mseg, uint16 mwin)
{
struct port *p;
int16 pnum,ret;
uint8 *pc;
/*
* check the IP number and don't allow broadcast addresses
*/
if (machine[3] == 255)
{
NU_Tcp_Log_Error (TCP_NO_BOARD_ADDRS, TCP_RECOVERABLE,
__FILE__, __LINE__);
return (-4);
}
#ifndef INTERRUPT
netsleep (0); /* make sure no waiting packets */
#endif
/*
* get the hardware address for that host, or use the one for the
* gateway all handled by 'netdlayer' by ARPs.
*/
#ifndef POINT_TO_POINT
pc = netdlayer (machine); /* we have ether? */
if (pc == NU_NULL)
{ /* cannot connect to local machine */
NU_Tcp_Log_Error (TCP_NO_LOC_HOST, TCP_RECOVERABLE,
__FILE__, __LINE__);
/* Increment the number of packets that could not be delivered. */
SNMP_ipOutNoRoutes_Inc;
return (NU_ARP_FAILED);
}
#endif
if ((pnum = makeport()) < 0) /* set up port structure and packets */
return (NU_NO_PORT_NUMBER);
p = portlist[pnum]; /* create a new port */
/* make a copy of the ip number that we are trying for */
memcpy ((void *)p->tcpout.i.ipdest, (const void *)machine, 4);
/* pseudo header needs it */
memcpy ((void *)p->tcps.dest, (const void *)machine, 4);
#ifndef POINT_TO_POINT
/* load it up */
memcpy ((void *)p->tcpout.d.dest, (const void *)pc, DADDLEN);
#endif
/* Add in machine specific settings for performance tuning */
if (rto >= MINRTO)
p->rto = rto; /* starting retrans timeout */
if (mtu <= MTU) /* largest packet space we have */
p->sendsize = mtu; /* maximum transmit size for that computer */
if (mwin <= WINDOWSIZE) /* buffer size is the limit */
p->credit = mwin; /* most data that we can receive at once */
/*
* Make the connection, if you can, we will get an event notification
* later if it connects. Timeouts must be done at a higher layer.
*/
ret = doconnect (pnum, service, mseg);
return (ret);
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* doconnect(int16, uint16, uint16) */
/* */
/* DESCRIPTION */
/* */
/* This routine sends the actual packet out to try and establish a */
/* connection. */
/* */
/* CALLED BY */
/* netxopen */
/* */
/* CALLS */
/* */
/* intswap */
/* Send_SYN_FIN */
/* */
/* HISTORY */
/* */
/* Maiqi Qian 12/05/96 Fixed the problem of SOR0229 */
/* 1. Move assignment of SSYNS to port->state after Send_SYN_FIN(). */
/* */
/*************************************************************************/
int16 doconnect(int16 pnum, uint16 service, uint16 mseg)
{
uint16 seg;
struct port *prt;
/* Get a pointer to the port. */
prt = portlist[pnum];
prt->tcpout.i.protocol=PROTTCP; /* this will be TCP socket */
prt->tcpout.t.dest=intswap(service); /* for example, telnet=23 */
prt->out.port=service; /* service same as port num */
prt->tcpout.t.flags=TSYN; /* want to start up sequence */
prt->tcpout.t.ack=0; /* beginning has no ACK */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -