不走心
#include <sys/socket.h>int socket (int domain, int type, int protocol); //socket_id / -1int shudown (int sockfd, int how /* SHUT_RD, SHUT_WR, SHUT_RDWR */); //0 / -1
#include <arpa/inet.h>uint32_t htonl (uint32_t hostint32); //h, hostuint16_t honns (uint16_t hostint16); //l, longuint32_t ntohl (uint32_t netint32); //n, networkuint16_t ntohs (uint16_t netint16); //s, short //byte series
#include <netinet/in.h>typedef uint16_t in_port_t;typedef uint32_t in_addr_t;struct sockaddr {#ifdef bsd unsigned char sa_len; //total length#endif sa_family_t sa_family; //address family char sa_data[]; //variable-length data};struct in_addr { in_addr_t s_addr; //ipv4 address};struct sockaddr_in { sa_family_t sin_family; //address family in_port_t sin_port; //port number#ifdef linux struct in6_addr sin6_addr; // unsigned char sin_zero[8];#else struct in_addr sin_addr; //ipv4 address#endif};struct in6_addr { uint8_t s6_addr[16]; //ipv6 address };struct sockaddr_in6 { sa_family_t sin6_family; //address family in_port_t sin6_port; //port number uint32_t sin6_flowinfo; //traffic class and flow info? struct in6_addr sin6_addr; //ipv6 address uint32_t sin6_scope_id; //set of interface for scope?};
推薦閱讀:
※我們到底選擇哪一款開源的Socket框架?
※Python之Socket通信與線程
※leader/follower, 半同步半非同步 和 事件驅動的關係是什麼?
※Socket(三)製作基本包結構
※Socket編程(C語言實現):socket()函數英文翻譯
TAG:Socket |