惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
WordPress大学
WordPress大学
O
OpenAI News
量子位
Last Week in AI
Last Week in AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
小众软件
小众软件
有赞技术团队
有赞技术团队
V
V2EX
宝玉的分享
宝玉的分享
月光博客
月光博客
腾讯CDC
IT之家
IT之家
博客园 - 【当耐特】
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Tenable Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost
美团技术团队
博客园 - 三生石上(FineUI控件)
博客园_首页
博客园 - Franky
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
博客园 - 司徒正美
Project Zero
Project Zero
Cyberwarzone
Cyberwarzone
博客园 - 叶小钗
雷峰网
雷峰网
Latest news
Latest news
S
SegmentFault 最新的问题
罗磊的独立博客
Help Net Security
Help Net Security
Hugging Face - Blog
Hugging Face - Blog
Jina AI
Jina AI
P
Proofpoint News Feed
L
LINUX DO - 热门话题
爱范儿
爱范儿
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
K
Kaspersky official blog
A
Arctic Wolf
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
GRAHAM CLULEY
F
Fortinet All Blogs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
PCI Perspectives
PCI Perspectives
Security Archives - TechRepublic
Security Archives - TechRepublic

博客园 - Jeff

4个月 C++ 有限状态机 POJ1019 POJ1035 POJ1007 POJ1005 ONLINE_JUDGE Linux shell定时器 怪异的grep结果 URL2FILE C primer笔记 Vxworks增加system call C语言常用宏定义技巧 分苹果 为什么选择SMP而不是AMP RTP memory in Vxworks Windriver的项目类型 RTP affinity Symmetric multiprocessing (SMP)
Socket
Jeff · 2011-11-03 · via 博客园 - Jeff

2011-11-03 14:22  Jeff  阅读(774)  评论()    收藏  举报

创建一个socket.

int socket
    (
    int domain,    /* address family (AF_xxx)     */
    int type,      /* socket type (SOCK_xxx)      */
    /*UDP: SOCK_DGRAM; TCP:SOCK_STREAM */
    int protocol   /* socket protocol (usually 0) */
    )

setsockopt - set socket options:

setsockopt (sock, SOL_SOCKET, SO_SNDBUF, &optval, sizeof (optval));

The value at is an integer (type `int') that specifies the size of the socket-level send buffer to be allocated. When stream, datagram or sequential packet sockets are created, each transport protocol reserves a set amount of space at the socket level for use when the sockets are attached to a protocol. For TCP, the default size of the send buffer is 8192 bytes. For UDP, the default size of the send buffer is 9216 bytes. For COMP, it is 64kbytes. Socket-level buffers are allocated dynamically from the mbuf pool.

setsockopt (sock, SOL_SOCKET, SO_RCVBUF, &optval, sizeof (optval));
setsockopt
    (
    int s,              /* target socket */
    int level,          /* protocol level of option */
    int optname,        /* option name */
    char *optval,       /* pointer to option value */
    int optlen          /* option length */
    )

bind:bind a name to a socket This routine associates a network address (also referred to as its "name") with a specified socket so that other processes can connect or send to it. When a socket is created with socket(), it belongs to an address family but has no assigned name.

bind
    (
    int s,                      /* socket descriptor */
    struct sockaddr *name,      /* name to be bound */
    int namelen                 /* length of name */
    )

getsockname - get a socket name This routine gets the current name for the specified socket s. The parameter namelen should be initialized to indicate the amount of space referenced by name. On return, the name of the socket is copied to name and the actual size of the socket name is copied to

.
getsockname
    (
    int s,                      /* socket descriptor */
    struct sockaddr *name,      /* where to return name */
    int *namelen                /* space available in name, later */
                                /* filled in with actual name size */
    )
recvfrom - receive a message from a socket This routine receives a message from a datagram socket regardless of whether it is connected. If from is non-zero, the address of the sender's socket is copied to it. The value-result parameter pFromLen should be initialized to the size of the from buffer. On return, pFromLen contains the actual size of the address stored in from.
recvfrom
    (
    FAST int             s,         /* socket to receive from */
    FAST char            *buf,      /* pointer to data buffer */
    FAST int             bufLen,    /* length of buffer */
    FAST int             flags,     /* flags to underlying protocols */
    FAST struct sockaddr *from,     /* where to copy sender's addr */
    FAST int             *pFromLen  /* value/result length of  */
    )
sendto - send a message to a socket This routine sends a message to the datagram socket named by to The socket s is received by the receiver as the sending socket.
int sendto
    (
    FAST int             s,             /* socket to send data to */
    FAST caddr_t         buf,           /* pointer to data buffer */
    FAST int             bufLen,        /* length of buffer */
    FAST int             flags,         /* flags to underlying protocols */
    FAST struct sockaddr *to,           /* recipient's address */
    FAST int             tolen          /* length of  sockaddr */
    )