zoukankan      html  css  js  c++  java
  • [linux]Socket编程的头文件

    socket编程中需要用到的头文件 
    sys/types.h:数据类型定义
    sys/socket.h:提供socket函数及数据结构
    netinet/in.h:定义数据结构sockaddr_in
    arpa/inet.h:提供IP地址转换函数
    netdb.h:提供设置及获取域名的函数
    sys/ioctl.h:提供对I/O控制的函数
    sys/poll.h:提供socket等待测试机制的函数
     
    其他在网络程序中常见的头文件 
    unistd.h:提供通用的文件、目录、程序及进程操作的函数
    errno.h:提供错误号errno的定义,用于错误处理
    fcntl.h:提供对文件控制的函数
    time.h:提供有关时间的函数
    crypt.h:提供使用DES加密算法的加密函数
    pwd.h:提供对/etc/passwd文件访问的函数
    shadow.h:提供对/etc/shadow文件访问的函数
    pthread.h:提供多线程操作的函数
    signal.h:提供对信号操作的函数
    sys/wait.h、sys/ipc.h、sys/shm.h:提供进程等待、进程间通讯(IPC)及共享内存的函数
     
    建议: 在编写网络程序时,可以直接使用下面这段头文件代码
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netdb.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #include <errno.h>
    #include <malloc.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #include <sys/ioctl.h>
    #include <stdarg.h>
    #include <fcntl.h>
    #include <fcntl.h>
     

    涉及到用户权限及密码验证问题时加入如下语句:
    #include <shadow.h>
    #include <crypt.h>
    #include <pwd.h> 
    需要注意的是,应该在编译时链接加密算法库,即增加编译选项:
    -lcrypt
      

    涉及到文件及时间操作加入如下语句: 
    #include <sys/time.h>
    #include <utime.h>
    #include <time.h>
    #include <sys/stat.h>
    #include <sys/file.h>
     

    涉及到多进程操作时加入如下语句: 
    #include <sys/wait.h>
    #include <sys/ipc.h>
    #include <sys/shm.h>
    #include <signal.h> 
     

    涉及到多线程操作时加入如下语句: 
    #include <pthread.h>
    #include <sys/poll.h>
    需要注意的是,应该在编译时链接线程库,即增加编译选项:
    -lthread
  • 相关阅读:
    NOIP2011 D1T1 铺地毯
    NOIP2013 D1T3 货车运输 倍增LCA OR 并查集按秩合并
    POJ 2513 trie树+并查集判断无向图的欧拉路
    599. Minimum Index Sum of Two Lists
    594. Longest Harmonious Subsequence
    575. Distribute Candies
    554. Brick Wall
    535. Encode and Decode TinyURL(rand and srand)
    525. Contiguous Array
    500. Keyboard Row
  • 原文地址:https://www.cnblogs.com/hermit/p/3627488.html
Copyright © 2011-2022 走看看