




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
Linux2.4網(wǎng)絡(luò)內(nèi)核源代碼閱讀筆記
應(yīng)用層網(wǎng)絡(luò)接口
#include<sys/types.h>
#include<sys/socket.h>
intsocket(intfamily,inttype,intprotocol)
/東服務(wù)器與客戶端都調(diào)用socket。來建立socket*/
其中:(1)family指明套節(jié)字協(xié)議族,其值包括:
AF_UNIX(UNIX內(nèi)部協(xié)議族)
AF_INET(Internet協(xié)議族)
AF_NS(XeroxNs協(xié)議,TCP/IP編程取該值)
AF_IMPLINK(IMP鏈接層)
(2)type指明套接字類型,取值有:
SOCK_STREAM(流套接字)
SOCK_DGRAM(數(shù)據(jù)報套接字)
SOCK_RAW(原始套接字)
SOCK_SEQPACKET(定序分組套接字)
股情況卜.,前兩個參數(shù)的組合的可以決定所使用的協(xié)議,這時第三個參數(shù)被置為0,如果第一個參數(shù)為AFJNET
第:個參數(shù)選SOCK_STREAM,則使用的協(xié)議為TCP;第.個參數(shù)選SOCK_DGRAM,則使用的協(xié)議為UDP:
當(dāng)?shù)冢簜€參數(shù)選SOCK_RAW時,使用的協(xié)議為IP。值得指出的是并不是所有的族和類型的組合都是合法的,
具體請查閱相關(guān)資料。該系統(tǒng)調(diào)用若成功則返一個類似文件描述符,稱為套接口描述字,可以像文件描述符
那樣用read和write對其進(jìn)行I/O操作。當(dāng)一個進(jìn)程使用完該軟插座時,需用close(<描述符〉)關(guān)閉。
intbind(intsocketfd,structsockaddrjn*localaddr,sizeof(structsockaddrjn))
/*服務(wù)器端Bind系統(tǒng)調(diào)用*/
其中:
(1)第一個參數(shù)socketfd是前步socket。系統(tǒng)調(diào)用返回的套節(jié)字描述符。
(2)笫二個參數(shù)被捆向本地地址的一種結(jié)構(gòu),該結(jié)構(gòu)在sys/netinet/in.h中定義:
structsockaddr_in{
shortsin_family;/*socket。系統(tǒng)調(diào)用的協(xié)議族如AF_INET*/
u_shortsin_port;/*網(wǎng)絡(luò)字節(jié)次序形式的端口號碼*/
structin_addrsin_addr;/*網(wǎng)絡(luò)字節(jié)次序形式的網(wǎng)絡(luò)地址*/
charsin_zero[8];
):
/'一臺機(jī)器上的每一個網(wǎng)絡(luò)程序都使用一個各自獨立的網(wǎng)絡(luò)端口號。如telnet使用23端口
ftp使用21端口,我們在寫程序的時候,可以通過調(diào)用getservbyname。函數(shù)從etc/services
輝文件中得到端口號,也可以使用htons(intportnum)函數(shù)k轉(zhuǎn)換為網(wǎng)絡(luò)字節(jié)次序
來得到,有些版本的unix規(guī)定1024以卜一端口只能被超級用戶使用,普通用戶只能使用
1025-32767之間的端I」號,網(wǎng)絡(luò)地址可以由gethostbyname(char*hostname)函數(shù)得到
(該函數(shù)與getservbyname()一樣都是以網(wǎng)絡(luò)字節(jié)次序形式返回所有在他們結(jié)構(gòu)中的數(shù)據(jù)),
參數(shù)hostname為etc/hosts文件中某個網(wǎng)絡(luò)地址所對應(yīng)的機(jī)器名,該函數(shù)返回一個類型為
hostent的結(jié)構(gòu)體指針,該結(jié)構(gòu)體hostent在netdb.h
*/
structhostent{
char*h_name;
char**h_aliases;
inth_addrtype;
inth」ength;/*地址長度*/
char**h_addr_list;
井defineh_addrh_addr_list[O];/*地址*/
}:
(3)笫:個參數(shù)為第.個結(jié)構(gòu)參數(shù)的長度,如果調(diào)用成功,bind返回0,否則將返回一1并設(shè)置errno。
intlisten(intsockedfd,intbacklog)
/*面向連接的服務(wù)器端系統(tǒng)調(diào)用listen,表示服務(wù)器愿意接受連接*/
它通常是在socket。和bind。調(diào)用后,在accept。調(diào)用前執(zhí)行。第二個參數(shù)指定accept
調(diào)用時系統(tǒng)可以等待多少個連接請求o
intnewsocket=accept(intsocketfd,structsockaddrjn*peer,int*addlen);
/*服務(wù)器調(diào)用accept,以等待客戶機(jī)調(diào)用connect進(jìn)行連接。*/
調(diào)用等待隊列中的第一個連接請求,并建立一個與socketfd一樣特征的套接字。
如果沒有等待的連接請求,此調(diào)用阻塞調(diào)用者一直到連接請求到達(dá)。
連接成功后,該accept。調(diào)用將把對端的地址結(jié)構(gòu)和地址長度放到到參數(shù)peer和addlen中,
如果服務(wù)器端對客戶端的地址信息不感興趣,這兩個參數(shù)可以用0代替。
intconnect(intsocketfd,structsockaddrjn*servsaddr,intaddrlen)
/*客戶端調(diào)用connect。與服務(wù)器建立連接*/
客戶端取得套接字描述符后,用該connect。調(diào)用建立。服務(wù)器的連接,
參數(shù)socketfd為socket。調(diào)用返回的套接字描述符,第和第1個參數(shù)是指向想要連接的
目的地址的結(jié)構(gòu)和地址長度。調(diào)用成功返回0,否則將返回一1并設(shè)置errno.
/*通過建立的socket發(fā)送和接收數(shù)據(jù)*/
一旦建立連接,就可以通過調(diào)用read()和write像普通文件一樣向網(wǎng)絡(luò)上發(fā)送和接收數(shù)據(jù)。
intread(intsockfd,char*buff,intnbytes)
Read。有三個參數(shù):一個是套接字描述符,個為數(shù)據(jù)將被加入的數(shù)據(jù)緩沖區(qū),還仃一個整數(shù)指明要要接受的數(shù)據(jù)的長度,
Read。返Ml實際接收到的了節(jié)數(shù),出錯返回-1,遇到文件尾則返回0。
intwrite(intsockfd,char*buff,intnbytes)
Write。有三個參數(shù):?個是套接字描述符,個為指向需要發(fā)送的數(shù)據(jù)的緩沖區(qū),還有一個整數(shù)為要寫入到文件中的字節(jié)個數(shù),
它返回實際寫入的字」數(shù),出錯返回-10
intsend(intsockfd,char*buff,intnbytes,intflags);
intrecv(intsockfd,char*buff,intnbytes,intflags);
也可以調(diào)用send和recv來對套節(jié)字進(jìn)行讀寫,其調(diào)用與基本的read和write系統(tǒng)調(diào)用相似,只是多了一個發(fā)送方式參數(shù)flags,
intsendto(intsockfd,char*buff,intnbytes,intflags,structsockaddr*to,intaddrlen);
intrecvfrom(intsockfd,char*buff,intnbytes,intflags,structsockaddr*from,intaddrlen);
對于使用無連接協(xié)議的服務(wù)器程序和客戶端程序的流程,
客戶端程序并不和服務(wù)器程序建迂連接,它是通過使用服務(wù)器地址作為參數(shù)的sendto()系統(tǒng)調(diào)用,
發(fā)送一個數(shù)據(jù)報給服務(wù)器的。同樣,服務(wù)器并不接受客戶端的連接,而是川recvfrom()調(diào)用等待從客戶端來的數(shù)據(jù)。
這些調(diào)用與標(biāo)準(zhǔn)的系統(tǒng)調(diào)用read()^11write。相似。
這些調(diào)用需要附加的參數(shù).Flag參數(shù)可以是。或者下列常數(shù):
MSG_OOB接受或發(fā)送綁定外的數(shù)據(jù)
MSG_PEEK監(jiān)視進(jìn)入信息
MSG_DONTROUTE繞過路由
intclose(socketfd)
/*退出程序時,應(yīng)按正常方式關(guān)閉套節(jié)字號
Socket及協(xié)議管理層
include\linux\fs.h
描述:ljsocket相關(guān)的文件系統(tǒng)部分結(jié)構(gòu)體
Structinode
structinode{
structIist_headi_hash;
structlist_headUist;
structlist_headi_dentry;
structlist_headi_dirty_buffers;
structlist_headi_dirty_data_buffers;
unsignedlongLino;
atomic_ti_count;
kdev_ti_dev;
umode_ti_mode;
nlink_ti.nlink;
uid_tLuid;
gid_ti_gid;
kdev_ti_rdev;
lofOi_size;
time_ti_atime;
i_mtime;
time_ti_ctime;
unsignedinti_blkbits;
unsignedlongi_blksize;
unsignedlongi_blocks;
unsignedlongi_version;
structsemaphorei_sem;
structsemaphorei_zombie;
structinode_operations*i_op;
structfile_operations*i_fop;/*former->i_op->default_file_ops*/
structsuper_block*i_sb;
wait_queue_head_ti_wait;
structfile_lock*i_flock;
structaddress_space*i_mapping;
structaddress_spacei_data;
structdquot*i_dquot[MAXQUOTAS];
/*Thesethreeshouldprobablybeaunion*/
structlist_headi_devices;
structpipe_inode_info*i_pipe;
structblock_device*i_bdev;
structchar_device*i_cdev;
unsignedlongi_dnotify_mask;/*Directorynotifyevents*/
structdnotify_struct*i_dnotify;/*fordirectorynotifications*/
unsignedlongi_state;
unsignedintijlags;
unsignedchari_sock;
atomic_ti_writecount;
unsignedinti_attr_flags;
_u32Lgeneration;
union{
structminix_inode_infominix__i;
structext2_inode_infoext2_i;
structext3_inode_infoext3_i;
structhpfs_inode_infohpfs_i;
structntfs_inode_infontfs_i;
structmsdos_inode_infomsdos_i;
structumsdos_inode_infbumsdos_i;
structiso_inode_infoisofis_i;
structnfs_inode_infonfs_i;
structsysv_inode_infosysv_i;
structaffs_inode_infoaffs_i;
structufs_inode_infoufs_i;
structefs_inode_infoefs_i;
structromfs_inode_inforomfs_i;
structshmem_inode_infbshmem_i
structcoda_inode_infocoda_i;
structsmb_inode_infosmbfs_i;
structhfs_inode_infohfs_i;
structadfs_inode_infoadfs_i;
structqnx4_inode_infbqnx4_i;
structreiserfs_inode_inforeiserfs_i;
structbfs_inode_infobfs_i;
structudf_inode_infoudU;
structncp_inode_infoncpfs_i;
structproc_inode_infoproc_i;
structsocketsocket_i;
structusbdev_inode_infousbdev_i
structjffis2_inode_infojffs2_i;
void*generic_ip;
}u;
);
structfile
structfile{
structlist_headfjist;
structdentry*f_dentry;
structvfsmount*Cvfsmnt;
structfileoperations*f,op;
atomic_tf_count;
unsignedintLflags;
mode_tf_mode;
lofLtf_pos;
unsignedlongJreada,匚ramax,Jraend,匚ralen,Lrawin;
structfbwn__structf_owner;
unsignedintLuid,fLgid;
intCerror;
unsignedlongCversion;
/*neededforttydriver,andmaybeothers*/
void*private_data;
/*preallocatedhelperkiobuftospeedupO_DIRECT*/
structkiobuf*Mobuf;
longCiobuf_lock;
);
structfile_operations
/*
*NOTE:
*read,write,polkfsync,readv,writevcanbecalled
*withoutthebigkernellockheldinallfilesystems.
*/
structfile_operations{
structmodule"owner;
loff_t(*llseek)(structfile*,loff_t,int);
ssize_t(*read)(structfile*,char*,size_t,lofLt*);
ssize_t(*write)(structfile*,constchar*,size_t,lofO*);
int(*readdir)(structfile*,void*,filldir_t);
unsignedint(*poH)(structfile*,structpoll_table_struct*);
int(*ioctl)(structinode*,structfile*,unsignedint,unsignedlong);
int(*mmap)(structfile*,structvm_area_struct*);
int(*open)(structinode*,structfile*);
int(*flush)(structfile*);
int(*release)(structinode*,structfile*);
int(*fsync)(structfile*,structdentry*,intdatasync);
int(*fasync)(int,structfile*,int);
int(*lock)(structfile*,int,structfile_lock*);
ssize_t(*readv)(structfile*,conststructiovec*,unsignedlong,lofO*);
ssize_t(*writev)(structfile*,conststructiovec*,unsignedlong,lofLt*);
ssize_t(*sendpage)(structfile*,stmctpage*,int,size_t,loffLt*,int);
unsignedlong(*get_unmapped_area)(structfile*,unsignedlong,unsignedlong,unsigned
long,unsignedlong);
);
include\linux\skbuff.h
structsk_buff_head
structsk_buff_head{
/*Thesetwomembersmustbefirst.*/
structsk_buff*next;
structsk_buff*prev;
―u32qlen;
spinlock_tlock;
);
structsk_buff
structsk_buff{
/*Thesetwomembersmustbefirst.*/
structsk_buff*next;/*Nextbufferinlist*/
structsk_buff*prev;/*Previousbufferinlist*/
structsk_bufLhead*list;/*Listweareon*/
structsock*sk;/*Socketweareownedby*/
structtimevalstamp;/*Timewearrived*/
structnet_device*dev;/*Devicewearrivedon/areleavingby*1
/*Transportlayerheader傳輸層頭部結(jié)構(gòu)體*/
union
(
structtcphdr*th;
structudphdr*uh;
structicmphdr*icmph;
structigmphdr*igmph;
structiphdr*ipiph;
structspxhdr*spxh;
unsignedchar*raw;
}h;
/*Networklayerheader網(wǎng)絡(luò)層頭部結(jié)構(gòu)體*/
union
(
structiphdr*iph;
structipv6hdr*ipv6h;
structarphdr*arph;
structipxhdr*ipxh;
unsignedchar*raw;
}nh;
/*Linklayerheader數(shù)據(jù)鏈路層頭部結(jié)構(gòu)體*/
union
(
structethhdr*ethemet;
unsignedchar*raw;
}mac;
/*該數(shù)據(jù)報的傳輸路由信息結(jié)構(gòu)體*/
structdst_entry*dst;
*Thisisthecontrolbuffer.Itisfreetouseforevery
*layer.Pleaseputyourprivatevariablesthere.Ifyou
*wanttokeepthemacrosslayersyouhavetodoaskb_clone()
*first.ThisisownedbywhoeverhastheskbqueuedATM.
*1
/*這個字符數(shù)組是一個控制緩沖區(qū),每一層都可以自由使用。
請把你的私有變量存放在這兒。如果你想要這個數(shù)組的數(shù)據(jù)
在每一層都可以使用,那么你必須調(diào)用skb_clone()函數(shù)。
*/
charcb(48];
unsignedintlen;/*Lengthofactualdata整個數(shù)據(jù)報的實際長度*/
unsignedintdata_len;
unsignedintcsum;/*Checksum*/
unsignedchar_unused,/*Deadfield,maybereused*/
cloned,/*headmaybecloned(checkrefcnttobesure).*/
pkt_type,/*Packetclass*/
ip_summed;/*DriverfedusanIPchecksum*/
_u32priority;/*Packetqueueingpriority*/
atomic_tusers;/*Usercount-seedatagram.c,tcp.c*/
unsignedshortprotocol;/*Packetprotocolfromdriver.*1
unsignedshortsecurity;/*Securitylevelofpacket列
unsignedinttruesize;/*Buffersize整個緩沖區(qū)的大小*/
unsignedchar*head;/*Headofbuffer緩沖區(qū)起始地址*/
unsignedchar*data;/*Dataheadpointer協(xié)議數(shù)據(jù)報的起始地址*/
unsignedchar*tail;/*Tailpointer協(xié)議數(shù)據(jù)報尾地址*/
unsignedchar*end;/*Endpointer整個緩沖區(qū)的尾地址*/
void(*destructor)(structsk_buff*);/*Destructfunction*/
#ifdefCONFIG_NETFILTER
/*Canbeusedforcommunicationbetweenhooks.*/
unsignedlongnfmark;
/*Cacheinfo*/
_u32nfcache;
/*Associatedconnection,ifany*/
structnfLct_info*nfct;
#ifdefCONFIG_NETFIETER_DEBUG
unsignedintnCdebug;
#endif
#endif/*CONFIGNETFILTER*/
#ifdefined(CONF!G_HIPPI)
union{
—u32ifield;
}private;
#endif
#ifdefCONFIG_NET_SCHED
―u32tc_index;/*trafficcontrolindex*/
#endif
);
include\net\sock.h
structinet_opt
structinet_opt{
intttl;/*TTLsetting*/
inttos;/*TOS*/
unsignedcmsg_flags;
structip_options*opt;
unsignedcharhdrincl;/*Includeheaders?*1
_u8/*MulticastingTTL*/
_u8mc_loop;/*Loopback*/
unsignedrecverr:1,
freebind:1;
_ul6id;1*IDcounterforDFpkts*/
_u8pmtudisc;
intmc_index;/*Multicastdeviceindex*/
_u32mc_addr;
structip_mc_socklist/*Grouparray*/
);
structtcp_opt
描述:Linux_2.4.1網(wǎng)絡(luò)套接字內(nèi)部包含了一個由tcp_opt結(jié)構(gòu)
組成的共計420個字節(jié)的傳輸控制塊
structtcp_opt{
inttcp_header_len;/*Bytesoftcpheadertosend*/
/*
*Headerpredictionflags
*0x5?10?16+snd_wndinnetbyteorder
*/
,u32pred_flags;
*RFC793variablesbytheirpropernames.Thismeansyoucan
*readthecodeandthespecsidebyside(andlaugh...)
*SeeRFC793andRFC1122.TheRFCwritestheseincapitals.
*/
_u32rcv_nxt;/*Whatwewanttoreceivenext*/
_u32snd_nxt;/*Nextsequencewesend*/
_u32snd_una;/*Firstbytewewantanackfor*/
_u32snd_sml;/*Lastbyteofthemostrecentlytransmittedsmallpacket*/
_u32rcv_tstamp;/*timestampoflastreceivedACK(forkeepalives)*/
_u32Isndtime;/*timestampoflastsentdatapacket(forrestartwindow)*/
/*DelayedACKcontroldata*/
struct{
一u8pending;/*ACKispending*/
一u8quick;/*Schedulednumberofquickacks*/
_u8pingpong;/*Thesessionisinteractive*/
_u8blocked;/*DelayedACKwasblockedbysocketlock*/
_u32ato;/*Predictedtickofsoftclock*/
unsignedlongtimeout;/*Currentlyscheduledtimeout*/
_u32Ircvtime;/*timestampoflastreceiveddatapacket*/
—u16last_seg_size;/*Sizeoflastincomingsegment*/
—ul6rcv_mss;/*MSSusedfordelayedACKdecisions*1
}ack;
/*Datafordirectcopytouser*/
struct{
structskbuffheadprequeue;
structtask__struct*task;
structiovec*iov;
intmemory;
intlen;
}ucopy;
—u32snd_wl1;/*Sequenceforwindowupdate*/
—u32snd_wnd;/*Thewindowweexpecttoreceive*/
―u32max_window;/*Maximalwindoweverseenfrompeer*/
_u32pmtu_cookie;/*Lastpmtuseenbysocket*/
_ul6mss_cache;/*Cachedeffectivemss,notincludingSACKS*/
_u!6mss_clamp;/*Maximalmss,negotiatedatconnectionsetup*/
—ul6ext_header_len;/*Networkprotocoloverhead(IP/IPv6options)*/
_u8ca_state;/*Stateoffast-retransmitmachine*/
一u8retransmits;/*NumberofunrecoveredRTOtimeouts.*/
_u8reordering;/*Packetreorderingmetric.*/
一u8queue_shrunk;/*Writequeuehasbeenshrunkrecently.*/
一u8defer_accept;/*Userwaitsforsomedataafteraccept()*/
/*RTTmeasurement*/
_u8backoff;/*backoff*/
_u32srtt;/*smothedroundtriptime?3*/
_u32mdev;/*mediumdeviation*/
_u32mdev_max;/*maximalmdevforthelastrttperiod*/
_u32rttvar;/*smoothedmdev_max*/
_u32rtt_seq;/*sequencenumbertoupdaterttvar*/
_u32rto;/*retransmittimeout*/
_u32packets_out:/*Packetswhichare"inflight"*/
_u32left_out;/*Packetswhichleavednetwork*/
_u32retrans_out;/*Retransmittedpacketsout*/
*Slowstartandcongestioncontrol(seealsoNagle,andKam&Partridge)
*/
—u32snd_ssthresh;/*Slowstartsizethreshold*/
―u32snd_cwnd;/*Sendingcongestionwindow*/
_ul6snd_cwnd_cnt;/*Linearincreasecounter*/
_ul6snd_cwnd_clamp;/*Donotallowsnd_cwndtogrowabovethis*/
_u32snd_cwnd_used;
―u32snd_cwnd_stamp;
/*Twocommonlyusedtimersinbothsenderandreceiverpaths.*/
unsignedlongtimeout;
structtimer_listretransmit_timer;/*Resend(noack)*/
structtimerjistdelack_timer;/*Ackdelay*/
/*out_of_order_queue用于接收無序得tcp包*/
structsk_bufLheadout_oLorder_queue;/*Outofordersegmentsgohere*/
/*OperationswhichareAF_INET{4,6}specific*/
structtcp_func^af_specific;
structsk_buff*send_head;/*Frontofstufftotransmit*/
structpage*sndmsg_page;/*Cachedpageforsendmsg*/
u32sndmsg_off;/*Cachedoffsetforsendmsg*/
—u32rcv_wnd;/*Currentreceiverwindow*/
—u32rcv_wup;/*rcv_nxtonlastwindowupdatesent*/
—u32write_seq;/*Tail(+1)ofdataheldintcpsendbuffer
_u32pushed_seq;/*Lastpushedseq,requiredtotalktowindows*/
―u32copied_seq;/*Headofyetunreaddata*/
Optionsreceived(usuallyonlastpacket,someonlyonSYNpackets).
*/
chartstamp_ok,/*TIMESTAMPseenonSYNpacket*/
wscale_ok,/*WscaleseenonSYNpacket*/
sack_ok;/*SACKseenonSYNpacket*/
charsaw_tstamp;/*SawTIMESTAMPonlastpacket*/
_u8snd_wscale;/*Windowscalingreceivedfromsender*/
一u8rcv_wscale;/*Windowscalingtosendtoreceiver*/
一u8nonagle;/*DisableNaglealgorithm?*/
_u8keepalive_probes;/*numofallowedkeepaliveprobes*/
PAWS/RTTMdata*/
_u32rcv_tsval;/*Timestampvalue*/
―u32rcv_tsecr;/*Timestampechoreply*/
_u32ts_recent;/*Timestamptoechonext*/
longts_recent_stamp;/*Timewestoredts_recent(foraging)*1
SACKsdata*/
_u16user_mss;/*mssrequestedbyuserinioctl*/
_u8dsack;/*D-SACKisscheduled*/
_u8eff_sacks;/*SizeofSACKarraytosendwithnextpacket*/
structtcp_sack_blockduplicate_sack[1];/*D-SACKblock*/
structtcp_sack_blockselective_acks[4];/*TheSACKSthemselves*/
―u32window_clamp;/*Maximalwindowtoadvertise*/
―u32rcv_ssthresh;/*Currentwindowclamp*/
一u8probes_out;/*unanswered0windowprobes*/
一u8num_sacks;/*NumberofSACKblocks*/
—ul6advmss;/*AdvertisedMSS*/
_u8syn_retries;/*numofallowedsynretries*/
_u8ecn_flags;/*ECNstatusbits.*/
_ul6prior_ssthresh;/*ssthreshsavedatrecoverystart*/
―u32lost_out;/*Lostpackets*/
―u32sacked_out;/*SACK'dpackets*/
―u32fackets_out;/*FACK'dpackets*/
―u32high_seq;/*snd_nxtatonsetofcongestion*/
―u32retrans_stamp;/*Timestampofthelastretransmit,
*alsousedinSYN-SENTtorememberstampof
*thefirstSYN.*/
―u32undo_marker;/*trackingretransstartedhere.*/
intundo_retrans;/*numberofundoableretransmissions.*/
_u32urg_seq;/*Seqofreceivedurgentpointer*/
一u!6urg_data;/*SavedoctetofOOBdataandcontrolflags*/
_u8pending;/*Scheduledtimerevent*/
_u8urg_mode;/*Inurgentmode*/
_u32snd_up;/*Urgentpointer*/
/*Thesyn_wait_lockisnecessaryonlytoavoidtcp_get_infohaving
*tograbthemainlocksockwhilebrowsingthelisteninghash
*(otherwiseit'sdeadlockprone).
*Thislockisacquiredinreadmodeonlyfromtcp_get_info()and
*it'sacquiredinwritemode_only_fromcodethatisactively
*changingthesyn_wait_queue.Allreadersthatareholding
*themastersocklockdon'tneedtograbthislockinreadmode
*tooasthesyn_wait_queuewritesarealwaysprotectedfrom
*themainsocklock.
*/
rwlock_tsyn_wait_lock;
structtcplistenopt*listen_opt;
/*FIFOofestablishedchildren*/
structopen_request^acceptjqueue;
structopenjrequest^acceptjqueueJail;
intwrite_pending;/*Awritetosocketwaitstostart.*1
unsignedintkeepalive_time;/*timebeforekeepalivetakesplace*/
unsignedintkeepalive_intvl;/*timeintervalbetweenkeepaliveprobes*/
intlinger2;
unsignedlonglast_synq_overflow;
);
structsock
structsock{
/*Socketdemultiplexcomparisonsonincomingpackets.*/
_u32daddr;/*ForeignIPv4addr*/
_u32rcv_saddr;/*BoundlocalIPv4addr*/
—u!6dport;/*Destinationport*/
unsignedshortnum;/*Localport*/
intbound_dev_if;/*Bounddeviceindexif!=0*/
/*Mainhashlinkageforvariousprotocollookuptables.*/
structsock*next;
structsock**pprev;
structsock*bind_next;
structsock**bind_pprev;
volatileunsignedcharstate,/*Connectionstate*/
zapped;/*Inax25&ipxmeansnotlinked*/
_ul6sport;/*Sourceport*/
unsignedshortfamily;/*Addressfamily*/
unsignedcharreuse;/*SO_REUSEADDRsetting*/
unsignedcharshutdown;
atomic_trefcnt;/*Referencecount*/
socket_lock_tlock;/*Synchronizer...*/
/*接收緩沖區(qū)字節(jié)長度*/
intrcvbuf;/*Sizeofreceivebufferinbytes*/
wait_queue_head_t*sleep;/*Sockwaitqueue*/
structdst_entry*dst_cache;/*Destinationcache*/
rwlock_tdst_lock;
/*接收隊列已經(jīng)提交的字節(jié)數(shù)*/
atomic_trmem_alloc;/*Receivequeuebytescommitted*/
/*接收的數(shù)據(jù)報的隊列號
structsk_buff_headreceive_queue;/*Incomingpackets*/
/*發(fā)送隊列已提交的字節(jié)數(shù)*/
atomic_twniem_alloc;/*Transmitqueuebytescommitted*/
/*發(fā)送數(shù)據(jù)報的隊列*/
structsk_bufL_headwrile_queue;/*Packetsendingqueue*/
atomic_tomem_alloc;/*nonis"option"or"other"*/
intwmem_queued;/*Persistentqueuesize*/
intfbrward_alloc;/*Spaceallocatedforward.*/
—u32saddr;/*Sendingsource*/
unsignedintallocation;/*Allocationmode*/
/*發(fā)送緩沖區(qū)的字節(jié)長度刃
intsndbuf;/*Sizeofsendbufferinbytes*/
structsock*prev;
/*Notallarevolatile,butsomeare,sowemightaswellsaytheyallare.
*XXXMakethisaflagword-DaveM
*/
volatilechardead,
done,
urginline,
keepopen,
linger,
destroy,
no_check,
broadcast,
bsdism;
unsignedchardebug;
unsignedcharrcvtstamp;
unsignedcharuse_write_queue;
unsignedcharuserlocks;
/*Holeof3bytes.Trytopack.*/
introute_caps;
intproc;
unsignedlonglingertime;
inthashent;
structsock*pair;
/*Thebacklogqueueisspecial,itisalwaysusedwith
*theper-socketspinlockheldandrequireslowlatency
*access.Thereforewespecialcaseit'simplementation.
*/
/*backlog是一個隊列,用于將該sock接收到的skb但是不能被及時處理的skb連接成
一個鏈表。
*/
struct{
structsk_buff*head;
structsk_buff
}backlog;
rwlock_tcallback_lock;
/*Errorqueue,rarelyused.*/
structsk_bufLheaderror_queue;
/*
sk結(jié)構(gòu)的操作指針prot注冊為與具體協(xié)議相關(guān)的
操作函數(shù)集structproto,實現(xiàn)了在協(xié)議上的抽象。
UDP協(xié)議為udp_prot?TCP為tcp_proto
*/
/*指定協(xié)議簇的內(nèi)部的協(xié)議處理函數(shù),它是套接口層與傳輸層之間的一個接口,
提供如bind,accept,close等操作*/
structproto*prot:
#ifdefined(CONFIG_IPV6)IIdefined(CONFIG_IPV6_MODULE)
union{
structipv6_pinfoaf_inet6;
}net_pinfo;
#endif
union{
structtcpoptaf_tcp;/*TCP傳輸控制結(jié)構(gòu)*/
#ifdefined(CONFIGJNET)IIdefined(CONFIG_INET_MODULE)
structraw_opttp_raw4;
#endif
#ifdefined(CONFIG」PV6)IIdefined(CONFIG_IPV6_MODULE)
structraw6_opttp_raw;
#endif/*CONFIG_IPV6*/
#ifdefined(CONHG_SPX)IIdefined(CONFIG_SPX_MODULE)
structspx_optaCspx;
#endif/*CONFIG_SPX*/
}tp_pinfo;r-傳輸協(xié)議控制塊聯(lián)合結(jié)構(gòu)*1
interr,err_soft;/*Softholdserrorsthatdon't
causefailurebutarethecause
ofapersistentfailurenotjust
,timedout'*/
/*表示當(dāng)前的監(jiān)聽隊列*/
unsignedshortack_backlog;
/*表示最大的監(jiān)聽隊列*/
unsignedshortmax_ack_backlog;
u32priority;
unsignedshorttype;
unsignedcharlocalroute;/*Routelocallyonly*/
unsignedcharprotocol;
structucredpeercred;
rcvlowat;
rcvtimeo;
sndtimeo;
#ifdefCONFIG.FILTER
/*SocketFilteringInstructions*/
structsk_filter*filter;
#endif/*CONFIG_FILTER*/
/*Thisiswherealltheprivate(optional)areasthatdon't
*overlapwilleventuallylive.
*/
union{
void*destruct_hook;
structunix_optafLunix;
#ifdefined(CONFIG」NET)IIdefined(CONFIG」NET_MODULE)
structinetoptaMnet;
#endif
#ifdefined(CONFIG_ATALK)IIdefined(CONFIG_ATALK_MODULE)
structatalk_sockaflat;
#endif
#ifdefined(CONFIG_IPX)IIdefined(CONFIG_IPX_MODULE)
structipx_opta匚ipx;
#endif
#ifdefined(CONFIG_DECNET)IIdefined(CONFIG_DECNET_MODULE)
structdn_scpdn;
#endif
#ifdefined(CONFIG_PACKET)IIdefined(CONFIG_PACKET_MODULE)
structpacket_opt*af_packet;
#endif
#ifdefined(CONFIG_X25)IIdefi
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 城市道路拓寬工程招標(biāo)合同(2篇)
- 企業(yè)辦公中提高效率的區(qū)塊鏈技術(shù)應(yīng)用
- 企業(yè)IP管理的創(chuàng)新之道區(qū)塊鏈與知識產(chǎn)權(quán)的結(jié)合
- 傳統(tǒng)醫(yī)學(xué)知識在健康管理方案中的應(yīng)用
- 2025年隔離接地開關(guān)項目合作計劃書
- 創(chuàng)新醫(yī)療信息化技術(shù)構(gòu)建高效醫(yī)療體系
- 以患者體驗為中心的遠(yuǎn)程醫(yī)療服務(wù)質(zhì)量提升策略研究
- 健康產(chǎn)業(yè)的新動力-醫(yī)療大數(shù)據(jù)的信息挖掘技術(shù)
- 2025年中國單針平縫附襯機(jī)數(shù)據(jù)監(jiān)測報告
- 衡陽一中月考試卷及答案
- 實驗室智能化設(shè)備的技術(shù)發(fā)展與趨勢
- 電廠化驗培訓(xùn)課件
- 2024年漢川市人民醫(yī)院高層次衛(wèi)技人才招聘筆試歷年參考題庫頻考點附帶答案
- 2024年03月湖南湖南岳陽農(nóng)商行招考10人筆試歷年參考題庫附帶答案詳解
- (新版)多旋翼無人機(jī)超視距駕駛員執(zhí)照參考試題庫(含答案)
- 湖北武漢武昌區(qū)武漢大學(xué)附屬中學(xué)2025屆高三第四次模擬考試數(shù)學(xué)試卷含解析
- 泄漏管理培訓(xùn)課件
- (2025年編輯)村規(guī)民約范文
- 電動托盤搬運車液壓原理培訓(xùn)
- 2024-2030年中國智慧教室行業(yè)發(fā)展?fàn)顩r分析及投資商業(yè)模式研究報告版
- 《ICT測試設(shè)備簡介》課件
評論
0/150
提交評論