hw.c

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

C
96
字号
/* hw.c * linqianghe@163.com * 2006-10-20 */#include "net-support.h"#include <stdio.h>#include <string.h>static short sVhwinit = 0;extern struct hwtype unspec_hwtype;extern struct hwtype loop_hwtype;extern struct hwtype ether_hwtype;static struct hwtype *hwtypes[] ={	&loop_hwtype,	&ether_hwtype,	&unspec_hwtype,    NULL};void hwinit(){	loop_hwtype.title = "Local Loopback";	unspec_hwtype.title = "UNSPEC";	ether_hwtype.title = "Ethernet";	sVhwinit = 1;}struct hwtype *get_hwntype(int type){	struct hwtype **hwp;	if( !sVhwinit )		hwinit();	hwp = hwtypes;	while( *hwp != NULL ){		if( (*hwp)->type == type )			return (*hwp);		hwp++;	}	return (NULL);}int hw_null_address(struct hwtype *hw, void *ap){	unsigned int i;	unsigned char *address = (unsigned char *)ap;	for (i = 0; i < hw->alen; i++)		if( address[i] )			return 0;	return 1;}void print_hwlist(int type) {	int count = 0;	char * txt;	struct hwtype **hwp;	if (!sVhwinit)		hwinit();	hwp = hwtypes;	while( *hwp != NULL ){		if( ((type == 1) && ((*hwp)->alen == 0)) || ((*hwp)->type == -1) ){			hwp++; 			continue;		}		if ((count % 3) == 0) fprintf(stderr,count?"\n    ":"    ");		txt = (*hwp)->name; if (!txt) txt = "..";		fprintf(stderr,"%s (%s) ",txt,(*hwp)->title);		count++;		hwp++;	}	fprintf(stderr,"\n");}struct hwtype *get_hwtype(const char *name){	struct hwtype **hwp;	if( !sVhwinit )		hwinit();	hwp = hwtypes;	while( *hwp != NULL ){		if( !strcmp((*hwp)->name, name) )			return (*hwp);		hwp++;	}	return (NULL);}

⌨️ 快捷键说明

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