⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 network layer - the kernel structures.htm

📁 Linux Kernel Programming by Examples(1)[Xeroo]
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0065)http://www.geocities.com/marco_corvi/games/lkpe/socket/socket.htm -->
<HTML><HEAD><TITLE>The network layer</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"><LINK 
href="Network layer - The kernel structures_file/style.css" rel=stylesheet>
<META content="MSHTML 6.00.2800.1170" name=GENERATOR></HEAD>
<BODY>
<H2>Network layer - The kernel structures</H2>
<DIV>References:<BR><BR></DIV><BR clear=all><BR clear=all><BR clear=all><B>The 
socket structure</B><BR>
<DIV>The structure <CODE>socket</CODE> is defined in the header file 
include/linux/net.h and is rather short, 
<UL>
  <LI><CODE>state</CODE>, the socket_state; 
  <LI><CODE>flags</CODE>, 
  <LI><CODE>ops</CODE>, pointer to the protocol functions; 
  <LI><CODE>inode</CODE>, pointer to the associated inode; 
  <LI><CODE>fasync_list</CODE>, asynchronous wake-up list; 
  <LI><CODE>file</CODE>, 
  <LI><CODE>sk</CODE>, pointer to a struct sock; 
  <LI><CODE>wait</CODE>, wait queue head; 
  <LI><CODE>type</CODE>, socket type; 
  <LI>
  <LI><CODE>passcred</CODE>, </LI></UL></DIV><B>The proto_ops and proto 
structures</B><BR>
<DIV>The protocol operations, struct <CODE>proto_ops</CODE>, are the user 
interface API. At the user level there is only one system call 
<CODE>sys_socket()</CODE>; the specific function is selected with an index. 
Indeed the user systemcalls do not map 1-1 on the propotol functions. 
<UL>
  <LI><CODE>bind(socket, umyaddr, addr_len)</CODE>, 
  <LI><CODE>release(socket)</CODE>, 
  <LI><CODE>connect(socket, uservaddr, addr_len, flags)</CODE>, 
  <LI><CODE>listen(socket, len)</CODE>, 
  <LI><CODE>accept(socket, new_socekt, flags)</CODE>, 
  <LI><CODE>getname(socket, uaddr, addr_len, peer)</CODE>, 
  <LI><CODE>sockedpair(socket_1, socket_2)</CODE>, 
  <LI><CODE>setsockopt(socket, level, optname, optval, optlen)</CODE>, 
  <LI><CODE>getsockopt(socket, level, optname, optval, optlen)</CODE>, 
  <LI><CODE>sendmsg(socket, msghdr, len, cookie)</CODE>, 
  <LI><CODE>recvmsg(socket, msghdr, len, flags, cookie)</CODE>, 
  <LI><CODE>mmap(file, socket, vma)</CODE>, 
  <LI><CODE>poll(file, socket, poll_table)</CODE>, 
  <LI><CODE>ioctl(socket, cmd, arg)</CODE>, 
  <LI><CODE>shutdown(socket, flags)</CODE>, 
  <LI><CODE>sendpage(socket, page, offset, size, flags)</CODE>, </LI></UL>The 
<CODE>proto</CODE> structure is a function table with pointers to routines for 
the IP protocol, that operate on the sock structure. The functions are, mainly, 
<UL>
  <LI><CODE>close(sock, timeout)</CODE> 
  <LI><CODE>connect(sock, uaddr, addr_len)</CODE> 
  <LI><CODE>disconnect(sock, flags)</CODE> 
  <LI><CODE>accept(sock, flags, error_pointer)</CODE> 
  <LI><CODE>ioctl(sock, cmd, arg)</CODE> 
  <LI><CODE>init(sock)</CODE> 
  <LI><CODE>destroy(sock)</CODE> 
  <LI><CODE>shutdown(sock, how)</CODE> 
  <LI><CODE>setsockopt(sock, level, optname, optval, optlen)</CODE> 
  <LI><CODE>getsockopt(sock, level, optname, optval, option)</CODE> 
  <LI><CODE>sendmsg(sock, msghdr, len)</CODE> 
  <LI><CODE>recvmsg(sock, msghdr, len)</CODE> 
  <LI><CODE>bind(sock, uaddr, addr_len)</CODE> 
  <LI><CODE>backlog_rcv(sock, sk_buff)</CODE> 
  <LI><CODE>get_port(sock, snum)</CODE> </LI></UL>The inet protocols are kept on 
the list <CODE>inetsw</CODE>. At start three static protocols are added, 
SOCK_STREAM, SOCK_DGRAM, and SOCK_RAW. These are permanent and cannot be 
modified. Other protocols can be registered and unregistered with the functions 
<CODE>inet_register_protosw</CODE> and <CODE>inet_unregister_protosw</CODE> 
respectively. These take as parameter a pointer to a struct 
<CODE>inet_protosw</CODE> which contains, among other things, 
<UL>
  <LI><CODE>type</CODE> and <CODE>protocol</CODE>, are the lookup key; 
  <LI><CODE>prot</CODE> points to a struct proto; 
  <LI><CODE>ops</CODE> points to a struct proto_ops; </LI></UL></DIV><BR 
clear=all><IMG height=480 
src="Network layer - The kernel structures_file/socket.gif" width=480> <BR 
clear=all><B>The sock structure</B><BR>
<DIV>The structure <CODE>sock</CODE> is defined in the header 
include/net/sock.h, and is rather large. There is a note in the source saying 
that it really should be better organized. Among other things it contains 
<UL>
  <LI><CODE>daddr</CODE>, and <CODE>dport</CODE>: the destination address and 
  port; 
  <LI><CODE>rcv_saddr</CODE>, local reveiving (bound) address; 
  <LI><CODE>num</CODE>, local port; 
  <LI><CODE>next</CODE>, <CODE>pprev</CODE>, <CODE>bind_next</CODE>, 
  <CODE>bind_pprev</CODE> hash linkage pointers; 
  <LI><CODE>state</CODE>, connection state; 
  <LI><CODE>saddr</CODE> and <CODE>sport</CODE>, source address and port; 
  <LI><CODE>family</CODE>, address family; 
  <LI><CODE>refcnt</CODE>, reference count; 
  <LI><CODE>sndbuf</CODE> and <CODE>rcvbuf</CODE>, size of sending and receiving 
  buffer in bytes; 
  <LI><CODE>sleep</CODE>, a wait_queue_head for the sock; 
  <LI><CODE>receive_queue</CODE>, sk_buff_head of incoming packets; 
  <LI><CODE>write_queue</CODE>, sk_buff_head of outgoing packets; 
  <LI><CODE>filter</CODE>, pointer to a sk_filter; 
  <LI><CODE>socket</CODE>, pointer to the socket; </LI></UL></DIV><B>The sk_buff 
structure</B><BR>
<DIV>The socket buffer structure <CODE>sk_buff</CODE> is defined in 
include/linux/skbuff.h, and contains (besides other things) 
<UL>
  <LI><CODE>next</CODE> and <CODE>prev</CODE>, because the socket buffer are 
  tied together in a doubly linked list; 
  <LI><CODE>list</CODE> is the socket buffer list to which this sk_buff belongs; 

  <LI><CODE>sk</CODE>, the socket the owns this sk_buff; 
  <LI><CODE>stamp</CODE>, time of arrival; 
  <LI><CODE>dev</CODE>, network device on which this sk_buff arrived; 
  <LI><CODE>h</CODE>, a pointer to the transport layer header; 
  <LI><CODE>nh</CODE>, a pointer to the network layer header; 
  <LI><CODE>mac</CODE>, a pointer to the link layer header; 
  <LI><CODE>cb[48]</CODE>, control buffer (for private data); 
  <LI><CODE>len</CODE>, length of actual data; 
  <LI><CODE>protocol</CODE>, packet protocol number from the driver; 
  <LI><CODE>head</CODE>, pointer to the head of buffer; 
  <LI><CODE>data</CODE>, pointer to the beginning of data; 
  <LI><CODE>tail</CODE>, pointer to the tail of data; 
  <LI><CODE>end</CODE>, pointer to the end of buffer; </LI></UL></DIV><BR 
clear=all><FONT size=-1>Marco Corvi - 2003</FONT> <!-- text below generated by server. PLEASE REMOVE --></OBJECT></LAYER>
<DIV></DIV></SPAN></STYLE></NOSCRIPT></TABLE></SCRIPT></APPLET>
<SCRIPT 
language=JavaScript>var PUpage="76001084"; var PUprop="geocities"; </SCRIPT>

<SCRIPT language=JavaScript 
src="Network layer - The kernel structures_file/pu5geo.js"></SCRIPT>

<SCRIPT language=JavaScript 
src="Network layer - The kernel structures_file/ygIELib9.js"></SCRIPT>

<SCRIPT language=JavaScript>var yviContents='http://us.toto.geo.yahoo.com/toto?s=76001084&l=NE&b=1&t=1057747006';yviR='us';yfiEA(0);</SCRIPT>

<SCRIPT language=JavaScript 
src="Network layer - The kernel structures_file/mc.js"></SCRIPT>

<SCRIPT language=JavaScript 
src="Network layer - The kernel structures_file/geov2.js"></SCRIPT>

<SCRIPT language=javascript>geovisit();</SCRIPT>
<NOSCRIPT><IMG height=1 alt=setstats 
src="Network layer - The kernel structures_file/visit.gif" width=1 
border=0></NOSCRIPT> <IMG height=1 alt=1 
src="Network layer - The kernel structures_file/serv.gif" width=1> <!-- w53.geo.scd.yahoo.com compressed/chunked Wed Jul  9 03:36:46 PDT 2003 --></BODY></HTML>

⌨️ 快捷键说明

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