Transcript Socket

Linux Networks
TCP/IP Networking Layers
BSD Socket Interface
INET Socket Layer
Create
Bind
Listen
Accept
Connect
回到第一頁
Network
Applications
User
Kernel
BSD Sockets
Socket Interface
INET Sockets
TCP
UDP
Protocol Layers
IP
Network Devices
PPP
SLIP
ARP
Ethernet
Linux Networking Layers
回到第一頁
files_struct
count
close_on_exec
open_fs
fd[0]
fd[1]
fd[255]
file
f_mode
f_pos
f_flags
f_count
f_owner
f_op
f_inode
f_version
inode
BSD Socket
File Operations
lseek
read
write
select
ioctl
close
fasync
socket
type
protocol
data
SOCK_STREAM
SOCK_STREAM
Address Family
socket operations
sock
type
protocol
socket
Linux BSD Socket Data Structure
回到第一頁
System Call

<net/socket.c>
 int
sys_socketcall(int call,
unsigned long *args);
 call
 <linux/net.h>
SYS_SOCKET --> socket()
 SYS_BIND
--> bind()
 ... ...

 args
 args[]
回到第一頁
family

<include/linux/socket.h>

AF_UNIX


AF_INET


Appletalk DDP
AF_X25


Novell IPX
AF_APPLETALK


Internet IP Protocol
AF_IPX


Unix domain sockets
Reserved for X.25 project
... ...
回到第一頁
type

<include/linux/socket.h>

SOCK_STREAM


SOCK_DGRAM


reliably-delivered message
SOCK_SEQPACKET


raw socket
SOCK_RDM


datagram (conn.less) socket
SOCK_RAW


stream (connection) socket
sequential packet socket
... ...
回到第一頁
protocol

<include/linux/in.h>

IPPROTO_IP


IPPROTO_ICMP


Transmission Control Protocol
IPPROTO_EGP


Internet Group Management Protocol
IPPROTO_TCP


Internet Control Message Protocol
IPPROTO_IGMP


Dummy protocol for TCP
Exterior Gateway Protocol
... ...
回到第一頁
socket(family, type, protocol)

<net/socket.c>
 sys_socket(...)
 get
an empty inode for socket
structure
 allocate a sock structure
 return the file descriptor of the
socket if success
回到第一頁
bind(fd, uaddr, addrlen)

<net/socket.c>
 sys_bind(...)
 bind
a name to a socket
 move the socket address to
kernel space
 address & port checking
回到第一頁
listen(fd, backlog)

<net/socket.c>
 sys_listen(...)
 allow
the protocol to do anything
necessary
 move a socket into listening state
回到第一頁
accept(fd, sockaddr, skaddrlen)

<net/socket.c>
 sys_accept(...)
 attempt
to create a new socket
 set up the link with the client
 wake up the client
 return the new fd
回到第一頁
connect(fd, uaddr, addrlen)

<net/socket.c>
 sys_connect(...)
 attempt
to connect to a socket
with the server address
 move the address to kernel space
回到第一頁