01lst01.c

来自「实战的linux socket编程--示例源码」· C语言 代码 · 共 40 行

C
40
字号
/* Listing 1.1 : * * Example of socketpair(2) function: */#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <errno.h>#include <string.h>#include <sys/types.h>#include <sys/socket.h>intmain(int argc,char **argv) {    int z;                  /* Status return code */    int s[2];               /* Pair of sockets */    /*     * Create a pair of local sockets :     */    z = socketpair(AF_LOCAL,SOCK_STREAM,0,s);    if ( z == -1 ) {        fprintf(stderr,            "%s: socketpair(AF_LOCAL,SOCK_STREAM,0)\n",            strerror(errno));        return 1;           /* Failed */    }    /*     * Report the socket file descriptors returned:     */    printf("s[0] = %d;\n",s[0]);    printf("s[1] = %d;\n",s[1]);    system("netstat --unix -p");    return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?