sockets.c

来自「一个基于linux的TCP/IP协议栈的实现」· C语言 代码 · 共 56 行

C
56
字号
/* sockets.h * linqianghe@163.com * 2006-10-20 */#include <sys/socket.h>#include <stdio.h>#include <unistd.h>#include "config.h"#include "sockets.h"#include "util.h"#include "net-support.h"#include "dummy_ipv4.h"#include "log.h"int skfd = -1;			/* generic raw socket desc.     */int sockets_open( int family ){	struct aftype **aft;	int sfd = -1;	static int force = -1;	if( force < 0 ){		force = 0;		if( kernel_version() < KRELEASE(2, 1, 0)  )			force = 1;		if( access("/proc/net", R_OK) )			force = 1;	}	for( aft = aftypes; *aft; aft++ ){		struct aftype *af = *aft;		int type = SOCK_DUMMY;		if( af->af == AF_UNSPEC )			continue;		if( family && family != af->af )			continue;		if( af->fd != -1 ){			sfd = af->fd;			continue;		}		if( !family && !force && af->flag_file ){			if (access(af->flag_file, R_OK))				continue;		}		af->fd = socket(af->af, type, IPPROTO_DUMMY );		if (af->fd >= 0)			sfd = af->fd;	}	if( sfd < 0 )		PR_ERR( "No usable address families found.\n" );	return sfd;}

⌨️ 快捷键说明

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