1、fcntl

头文件 #include <fcntl.h>

#include <fcntl.h>

定义函数 int fcntl(int fd , int cmd);

int fcntl(int fd,int cmd,long arg);

int fcntl(int fd,int cmd,struct flock * lock);

fcntl()用来操作文件描述符的一些特性。参数fd代表欲设置的文件描述词,参数cmd代表欲操作的指令。

其详细情况见参考中。

1】 http://linux.die.net/man/2/fcntl

2】 http://baike.baidu.com/view/1930855.htm

3】 http://blog.mcuol.com/User/lvembededsys/Article/2388_1.htm

4】 http://blog.chinaunix.net/space.php?uid=21461208&do=blog&cuid=1915256

2、setsockopt

    setsockopt()函数用于任意类型、任意状态套接口的设置选项值。尽管在不同协议层上存在选项,但本函数仅定义了最高的“套接口”层次上的选项。

1】 http://linux.die.net/man/2/setsockopt

2】 http://baike.baidu.com/view/569217.htm

3、inet_aton

   inet_aton() converts the Internet host address cp from the standard numbers-and-dots notation into binary data and stores it in the structure that inp points to. inet_aton() returns non-zero if the address is valid, zero if not.

The inet_addr() function也是相同功能。

1】 http://linux.die.net/man/3/inet_aton

2】 http://baike.baidu.com/view/1870333.htm

【3】http://linux.die.net/man/3/inet_addr

4、对于sockaddr_in结构体的定义,则不同头文件定义又不同。

struct sockaddr_in {

    sa_family_t    sin_family; /* address family: AF_INET */

    u_int16_t      sin_port;   /* port in network byte order */

    struct in_addr sin_addr;   /* internet address */

};

 

/* Internet address. */

struct in_addr {

    u_int32_t      s_addr;     /* address in network byte order */

};

1】 http://linux.die.net/man/7/ip

2】 http://baike.baidu.com/view/2355183.htm

5、htonl()

    将主机的无符号长整形数转换成网络字节顺序。

1】 http://baike.baidu.com/view/569196.html

2】 http://linux.die.net/man/3/htonl

6、gettimeofday

    The functions gettimeofday() and settimeofday() can get and set the time as well as a timezone.

1】 http://linux.die.net/man/2/gettimeofday

2】 http://blog.sina.com.cn/s/blog_4d61a7570100eci0.html

3】 http://zhidao.baidu.com/question/75454941

4http://hi.baidu.com/%B1%AB%B9%FA%CC%CE/blog/item/778bcc23d850f7ae4623e8a0.html

7、semctl

semctl() performs the control operation specified by cmd on the semaphore set identified by semid, or on the semnum-th semaphore of that set. (The semaphores in a set are numbered starting at 0.)

系统调用semctl用来执行在信号量集上的控制操作。

1】 http://linux.die.net/man/2/semctl

2】 http://baike.baidu.com/view/3803900.htm

3】 http://hi.baidu.com/rhose/blog/item/83e74dd74dcf0d1a3bf3cf5b.html

8、waitpid

    通过waitpid调用和wait调用来收集子进程的信息。

1】 http://www.cnblogs.com/mydomain/archive/2010/10/24/1859826.html

2】 http://baike.baidu.com/view/2365304.htm

3】 http://linux.die.net/man/2/waitpid

9、getopt

getopt()用来分析命令行参数。

int getopt(int argc, char * const argv[], const char *optstring);

调用一次,返回一个选项。在命令行选项参数再也检查不到optstring中包含的选项时,返回-1,同时optind储存第一个不包含在optstring中的选项的命令行参数。

字符串optstring可以下列元素,

1)单个字符,表示选项,

2)单个字符后接一个冒号:表示该选项后必须跟一个参数。参数紧跟在选项后或者以空格隔开。该参数的指针赋给optarg

3)单个字符后跟两个冒号,表示该选项后必须跟一个参数。参数必须紧跟在选项后不能以空格隔开。该参数的指针赋给optarg。(这个特性是GNU的扩展)。

getopt处理以'-’开头的命令行参数,如optstring="ab:c::d::",命令行为getopt.exe -a -b host -ckeke -d haha

在这个命令行参数中,-a-b就是选项元素,去掉'-'a,b,c就是选项。hostb的参数,kekec的参数。但haha并不是d的参数,因为它们中间有空格隔开。

默认情况下getopt会重新排列命令行参数的顺序,所以到最后所有不包含在optstring中的选项的命令行参数都排到最后。

getopt.exe -a ima -b host -ckeke -d haha,包含在optstring中命令行参数是:

-a -b host -ckeke -d

不包含在optstring中的参数为imahaha,所以重排后,如下所示:

最后命令行参数的顺序是: -a -b host -ckeke -d ima haha

如果optstring中的字符串以'+'加号开头或者环境变量POSIXLY_CORRE被设置。那么一遇到不包含选项的命令行参数,getopt就会停止,返回-1

1】 http://baike.baidu.com/view/2406693.htm

2】 http://linux.die.net/man/3/getopt

3】 http://www.cnitblog.com/zouzheng/archive/2007/04/02/25034.aspx

4】 http://blogold.chinaunix.net/u1/50826/showart_472964.html

5】 http://www.ibm.com/developerworks/cn/aix/library/au-unix-getopt.html

posted on 2013-01-18 09:16  一个人的天空@  阅读(1514)  评论(0编辑  收藏  举报