正在加载图片...
Data structures for socket Data structures for socket The easiest way to understand the abstraction ocket descriptor table (one per process Data structure for a socket When an application calls socket, the Os allocate a new data structure to hold the information needed for communicatio Fill in a new entry in the process' socket 0123 Pointers to other socket tructures descriptor table with a pointer to the data The system keeps a separate socket Operating System descriptor table for each process The application that creates the socket must make Threads in the process share the table. I procedures calls to fill in information in the socket data st Specifying an endpoint address Specifying an endpoint address ost A ocket connection (viral connection) ss and protocol por Other protocol families define their endpoint addresses in other accommodate multiple families of protocols, socket abstraction ock Adapter Card It allows each protocol family to specify endpoints however it likes. The socket abstraction defines an address family for each type of rotocol family can use one or more address families to define When a socket is created it does not have addre Bedore using a socket, must specify one or both end onstant AF INET. Both PF_INET and aF_ INET have the same value(2) Generic Address structure Generic Address structure Application may need to manipulate protocol In practice, the socket API provides declarations of addresses without knowing the details of how every predefined data types for address endpoints. protocol family defines its address representation. To accommodate such programs, the socket system structure es a generalized format that all endpoint struct sockaddr (address family, endp addr n that family) u char sa⊥en /*length of address*/ u char sa family; /*family of address*/ char sa data[141 preassigned address type5 哈工大计算机学院 李全龙 Network Application Development Socket Programming 25 Data structures for socket „ The easiest way to understand the abstraction „ When an application calls socket, the OS allocate a new data structure to hold the information needed for communication „ Fill in a new entry in the process’ socket descriptor table with a pointer to the data structure. „ The system keeps a separate socket descriptor table for each process „ Threads in the process share the table. 哈工大计算机学院 李全龙 Network Application Development Socket Programming 26 Data structures for socket „ The application that creates the socket must make additional procedures calls to fill in information in the socket data structure before the socket can be used. . 0: . 1: . Pointers to other socket structures 2: . 3: . . . Socket descriptor table (one per process) Operating System family:PF_INET service:sock_stream local IP: remote IP: . . . local port: remote port: Data structure for a socket 哈工大计算机学院 李全龙 Network Application Development Socket Programming 27 Specifying an endpoint address „ When a socket is created it does not have addresses „ Before using a socket, must specify one or both end addresses. Network (physical connection) Host B Process 2 Host A Process 1 Network Adapter Card Information Hiding Socket connection (virtual connection) 哈工大计算机学院 李全龙 Network Application Development Socket Programming 28 Specifying an endpoint address „ TCP/IP defines communication endpoint to consists of an IP address and protocol port number. „ Other protocol families define their endpoint addresses in other ways. „ To accommodate multiple families of protocols, socket abstraction does not specify how to define endpoint addresses nor does it define a particular protocol address format. „ It allows each protocol family to specify endpoints however it likes. „ The socket abstraction defines an address family for each type of address. „ A protocol family can use one or more address families to define address representation. „ TCP/IP protocols all use a single address rep, with the address family denoted by the symbolic constant AF_INET. „ Both PF_INET and AF_INET have the same value (2). 哈工大计算机学院 李全龙 Network Application Development Socket Programming 29 Generic Address Structure „ Application may need to manipulate protocol addresses without knowing the details of how every protocol family defines its address representation. „ To accommodate such programs, the socket system defines a generalized format that all endpoint addressed use. (address family, endpoint address in that family) Contains a constant that denotes one of the preassigned address type Contains an endpoint address using the standard representation for the specific address type 哈工大计算机学院 李全龙 Network Application Development Socket Programming 30 Generic Address Structure „ In practice, the socket API provides declarations of predefined data types for address endpoints. „ The most general structure is known as a sockaddr structure. struct sockaddr { u_char sa_len; /*length of address*/ u_char sa_family; /*family of address*/ char sa_data[14]; /*address itself*/ }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有