protocol.c
来自「一个基于linux的TCP/IP协议栈的实现」· C语言 代码 · 共 48 行
C
48 行
/* protocol.c * linqianghe@163.com * 2006-09-05 */#include "af_inet.h"#include "protocol.h"static DEFINE_SPINLOCK(myinet_proto_lock);int myinet_add_protocol( struct net_protocol *prot, unsigned char protocol ){ int hash, ret; hash = protocol & (MAX_INET_PROTOS - 1); spin_lock_bh( &myinet_proto_lock ); if( myinet_protos[hash] ){ ret = -1; }else{ myinet_protos[hash] = prot; ret = 0; } spin_unlock_bh( &myinet_proto_lock ); return ret;}int myinet_del_protocol(struct net_protocol *prot, unsigned char protocol){ int hash, ret; hash = protocol & (MAX_INET_PROTOS - 1); spin_lock_bh( &myinet_proto_lock ); if( myinet_protos[hash] == prot ){ myinet_protos[hash] = NULL; ret = 0; }else{ ret = -1; } spin_unlock_bh( &myinet_proto_lock ); synchronize_net(); return ret;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?