Posts Tagged ‘Unix Socket’

Unix网络编程 第13章 Daemon Processes and the inetd Superserver 笔记

# The syslogd daemon runs in an infinite loop that calls select, waiting for any one of its three descriptors to be readable. it reads the log message and does what the configuration file says to do with that message. If the daemon receives the SIGHUP signal, it rereads its configuration file. So, what are the three descriptors that the select system call is waiting for ?  1. A unix domain socket is created and bound to the pathname /var/run/log (/dev/log on some systems). 2. A udp socket is created and bound to port 514(the syslog service). 3. The pathname /devklog is opened. Any error messages from within the kernel appears as input on this device. Newer implementation disable the creation of the UDP socket, unless specified by the administrator, as allowing anyone to send UDP datagrams to this port opens the system up to denial-of-service attacks, where some one could fill up the filesystem.

# syslog函数的%m specification表示当前errno对应的error message.

# syslog函数的level和facility是为了配置如何处理各种log.配置文件是/etc/syslog.conf.

# logger命令可以产生log message。于是可以在shell脚本里使用logger.

# The purpose of the second fork is to guarantee that the daemon cannot automatically acquire a controlling terminal should it open a terminal device in the future. When a session leader without a controlling terminal opens a terminal device(that is not currently some other session's controlling terminal), the termianl becomes the controlling terminal of the session leader. But by calling fork a second time, we guarantee that the second child is no longer a session leader, so it cfannot acquire a controlling terminal. We must ignore SIGHUP because when the session leader terminates(the first child), all processes in the session(our second child)receive the SIGHUP signal.

# daemon通常把当前工作目录设为 / .如果不这样的话就会有可能使得不能unmount某些文件系统。

# On linux, /var/log/message is where the system send all LOG_USER messages after connecting from the same machine(e.g. localhost). Page370.

# 早期的Unix系统,早于4.3BSD.有很多服务像ftp, telnet, rlogin, tftp等都是以daemon的形式运行。每一个都要在进程表里占一个位置(each one took a slot in the process table).但是每个daemon大多数时间都在睡眠状态。从4.3BSD开始引入了inetd.

# inetd的配置对于UDP的wait_flag必须是wait.因为UDP socket只有一个.如果不wait话,parent存在可能性先于child进程得到CPU。而udp socket缓冲中的数据还未来得及读出。这样,inetd的select又返回这个socket可读。wait_flag的wait的意思就是要wait到fork出的子进程结束。而tcp socket会在accept返回的时候给子进程一个connected socket.父进程可以立即得到CPU执行select判断listenning socket是否可读。

# xinetd的配置采用每个服务一个配置文件.而inetd用一个monolithic configuration file.

# On a Berkely-derived kernel the timeout for a tcp connect is normally 75秒.

Be the first to comment - What do you think?  Posted by zausiu - December 27, 2011 at 00:59

Categories: Network, Tech Articles, Unix / Linux   Tags: ,

Unix网络编程 第十二章 IPv4 and IPv6 Interoperability

# Ethernet header contains a type fileld of 0x0800, which identifies the frame as an IPv4 frame.

# 若支持dual-stack的server既有IPv4又有IPv6。则IP层让server透明地既可处理IPv4又可处理IPv6.该server需要绑定到wildcard且未设置IPV6_V6ONLY socket option.

# UNP Page359 Figure 12.5 Summary of interoperability between IPv4 and IPv6 clients and servers.

# 尽可能用IPv6,  since an IPv6 client can still communicate with IPv4 servers, and vice versa.

Be the first to comment - What do you think?  Posted by zausiu - December 26, 2011 at 21:28

Categories: Network, Tech Articles, Unix / Linux   Tags:


# TCP 协议在1981年标准化,而SCTP协议则是在2000年由IETF组织标准化。IETF: Internet Engineering Task Force 互联网工程任务组成立于1985年。

# SCTP支持两种类型的socket. one to one(为了方便现有的tcp程序迁移到sctp) 和 one to many.

# sctp的sctp_bindx可以绑定多个地址,并且可以动态增删。但动态增删不影响已经存在的associations.不过各个unix分支不一定支持这个特性。

# sctp_getpaddrs和sctp_getladdrs分别是getpeername和gethostname的sctp版。They are designed with the concept of a multihoming aware transport protocol.

# sctp传输的报文是有边界的。sctp在传输层支持传输超大的message.

Be the first to comment - What do you think?  Posted by zausiu - December 17, 2011 at 16:58

Categories: Network, Tech Articles, Unix / Linux   Tags: ,

Next Page »