sock_ini.c

来自「dos 下 网络协议 dos 下 网络协议」· C语言 代码 · 共 64 行

C
64
字号
/*
 * sock_init - easy way to guarentee:
 *	- card is ready
 *	- shutdown is handled
 *	- cbreaks are handled
 *      - config file is read
 *	- bootp is run
 *
 * 0.1 : May 2, 1991  Erick - reorganized operations
 */

#include <copyright.h>
#include <wattcp.h>
#include <stdlib.h>

int _survivebootp = 0;
static char _initialized = 0;		// S. Lawson

void sock_exit( void )
{
    if (_initialized)			// S. Lawson
       tcp_shutdown();
    _initialized = 0;			// S. Lawson
}

// S. Lawson - keep an exiting sock_init()
void sock_init(void)
{
    int r;
    r=sock_init_noexit();
    if (r) exit(r);
}

int sock_init_noexit(void )			// S. Lawson
{
    int r;					// S. Lawson

    if (_initialized) return 0;			// S. Lawson
// S. Lawson    tcp_init();	/* must precede tcp_config because we need eth addr */
    r=tcp_init_noexit();	/* (S. Lawson) must precede tcp_config because we need eth addr */
    if (r) return r;		// S. Lawson
    _initialized=1;		// S. Lawson
    atexit(sock_exit);	/* must not precede tcp_init() incase no PD */
    tcp_cbrk( 0x10 );	/* allow control breaks, give message */

#ifndef SKIPINI // S. Lawson
    if (tcp_config( NULL )) {	/* if no config file use BOOTP w/broadcast */
#endif // SKIPINI  S. Lawson
	_bootpon = 1;
	outs("Configuring through BOOTP/DHCP\r\n");    // S. Lawson
#ifndef SKIPINI // S. Lawson
    }
#endif // SKIPINI  S. Lawson

    if (_bootpon)	/* non-zero if we use bootp */
	if (_dobootp()) {
	    outs("BOOTP/DHCP failed\r\n");             // S. Lawson
	    if ( !_survivebootp )
	       return 3;			       // S. Lawson
// S. Lawson		exit( 3 );
	}
    return 0;					       // S. Lawson
}

⌨️ 快捷键说明

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