?? bind.c~
字號:
/* bind.c: * * Demonstrating the bind(2) function * by establishing a Specific AF_INET * Socket Address: */#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <errno.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>/* * This function reports the error and * exits back to the shell : */static voidbail(const char *on_what) { perror(on_what); exit(1);}intmain(int argc,char **argv,char **envp) { int z; /* Status return code */ int sck_inet; /* Socket */ struct sockaddr_in adr_inet;/* AF_INET */ int len_inet; /* length */ /* Create an IPv4 Internet Socket */ sck_inet = socket(AF_INET,SOCK_STREAM,0); if ( sck_inet == -1 ) bail("socket()"); /* Create an AF_INET address */ memset(&adr_inet,0,sizeof adr_inet); adr_inet.sin_family = AF_INET; adr_inet.sin_port = htons(9000); inet_aton("127.0.0.24",&adr_inet.sin_addr); len_inet = sizeof adr_inet; /* Now bind the address to the socket */ z = bind(sck_inet, (struct sockaddr *)&adr_inet, len_inet); if ( z == -1 ) bail("bind()"); /* Display all of our bound sockets */ system("netstat -pa --tcp 2>/dev/null | " "sed -n '1,/^Proto/p;/bind/p'"); close(sck_inet); return 0;}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -