摘要: #include <unistd.h>#include <stdio.h>#include <errno.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>const char *file="locktest";int main(void){ int file_res; file_res=open(file,O_RDWR|O_CREAT|O_EXCL,0444); if(file_res == -1) { printf(&quo 阅读全文
posted @ 2012-10-17 23:00 Myths 阅读(468) 评论(0) 推荐(0) 编辑
摘要: 1 #include <sys/socket.h> 2 #include <sys/types.h> 3 #include <unistd.h> 4 #include <stdio.h> 5 #include <stdlib.h> 6 #include <string.h> 7 #include <netdb.h> 8 9 int main(int argc,char *argv[])10 {11 int tar_socket=socket(AF_INET,SOCK_STREAM,0);12 struct so 阅读全文
posted @ 2012-10-13 22:02 Myths 阅读(480) 评论(0) 推荐(0) 编辑
摘要: 1 #include <stdio.h> 2 #include <unistd.h> 3 #include <netdb.h> 4 5 int main(int argc,char *argv[]) 6 { 7 struct servent serv; 8 struct servent *serv_info=&serv; 9 10 serv_info=getservbyport(htons(atoi(argv[1])),NULL);/*第二个参数为协议类型,为NULL时自动匹配所有协议*/11 printf("%s\n%d\n", 阅读全文
posted @ 2012-10-13 17:05 Myths 阅读(401) 评论(0) 推荐(0) 编辑