[Denny] Linux network — tcp/ip
从个人知识库中自动导出. 更新时间 2012-08-19 01:02.
Linux network — tcp/ip
ROPERTIES:
:type: KnowledgeBase_Linux
:END:
| Function signature | Summary |
|---|---|
| int socket(int family, int type, int protocol); | 用于建立三元组中的协议族部分,即TCP或UDP |
| int bind(int sockfd, cost struct sockaddr * saddr, socklen_t addrlen); | 用于建立三元组中的本地IP地址和本地端口号部分。 |
| int listen( int sockfd, int backlog ); | 打开”监听套接字”. Note:当调用socket( )和bind( )后,虽然套接字已经建立起来,但是其状态是 CLOSED即关闭状态。 |
| int accept( int sockfd, struct sockaddr * client_addr, socklen_t *addrlen); | 当客户与服务器连接( connect )并且连接成功(三次握手)后 accept 则返回另一个套接字, 即”连接套接字” |
| int connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen); | 客户端使用这个系统调用来连接目的主机(服务器)的指定端口,以便和目的主机 ( 在 access 中等待 ) 进行通信。 |
目录
1 What is the loopback interface: 通过软件虚拟出的localhost网卡
http://unix.stackexchange.com/questions/1911/what-is-the-loopback-interface
The loopback networking interface is a virtual network device implemented entirely in software. All traffic sent to it "loops back" and just targets services on your local machine. eth0 tends to be the name of the first hardware network device (on linux, at least), and will send network traffic to remote machines. You might see it as en0, ent0, et0, or various other names depending on which OS you're using at the time. (It could also be a virtual device, but that's another topic) The loopback option used when mounting an ISO image has nothing to do with the networking interface, it just means that the mount command has to first associate the file with a device node (/dev/loopback or something with a similar name) before mounting it to the target directory. It "loops back" reads (and writes, if supported) to a file on an existing mount, instead of using a device directly.
2 socket state
State The state of the socket. Since there are no states in raw mode and usually no
states used in UDP, this column may be left blank. Normally this can be one of
several values:
ESTABLISHED The socket has an established connection.
SYN_SENT The socket is actively attempting to establish a connection.
SYN_RECV A connection request has been received from the network.
FIN_WAIT1 The socket is closed, and the connection is shutting down.
FIN_WAIT2 Connection is closed, and the socket is waiting for a
shutdown from the remote end.
TIME_WAIT The socket is waiting after close to handle packets still
in the network.
CLOSE The socket is not being used.
CLOSE_WAIT The remote end has shut down, waiting for the socket to
close.
LAST_ACK The remote end has shut down, and the socket is
closed. Waiting for acknowledgement.
LISTEN The socket is listening for incoming connections. Such
sockets are not included in the output unless you specify the
--listening (-l) or --all (-a) option.
CLOSING Both sockets are shut down but we still don't have all our
data sent.
UNKNOWN The state of the socket is unknown.
3 监听的ip地址类型
http://www.cnblogs.com/zhenjing/archive/2011/04/20/2021791.html
[root@localhost i386]# netstat -nlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2804/mysqld tcp 0 0 222.230.14.16:80 0.0.0.0:* LISTEN 4433/(squid) tcp 0 0 127.0.0.1:80 0.0.0.0:* LISTEN 4350/httpd tcp 0 0 127.0.0.1:2006 0.0.0.0:* LISTEN 27724/php tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 26234/master tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 27724/php tcp 0 0 :::22 :::* LISTEN 2674/sshd udp 0 0 0.0.0.0:16384 0.0.0.0:* 4433/(squid) udp 0 0 0.0.0.0:3130 0.0.0.0:* 4433/(squid) 我说的本地地址的四种类型: 0 0.0.0.0 222.230.14.16 127.0.0.1 ::: 都是本地地址为何要有这四种类型呢?都是代表什么含义和作用呢? 一般 0.0.0.0 表示 all or any address , 以 listen 0.0.0.0 來說 , 表示 listen 主机所有 interface 的 ip 位址 . 至於你說的 222.230.14.16 or 127.0.0.1 那都只是表示listen特定ip位址 而已 ::: 那表示 listen 主机所有 interface 的 ipv6 位址 .
4 This is a limitation in the IP protocol, with one IP address you can’t create more connections than the 65535 available local ports.
6 # –8<————————– separator ————————>8–
Time: 2012-08-19 00:56:07 CST

最好还是能做个PDF~
@HpyHacking
让我们先迭代完善一阵子吧。
因为里面是通过emacs org-mode维护的,如果要导出成pdf只是一两秒钟的事情. ^-^