想在Linux环境下学习C++ 网络编程的知识,需要用到<sys/socket.h>库,使用VScode能看到源代码,但是想更深入的了解各个参数的详细信息。
/* Create a new socket of type TYPE in domain DOMAIN, using
protocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically.
Returns a file descriptor for the new socket, or -1 for errors. */
extern int socket (int __domain, int __type, int __protocol) __THROW;
但是在cppreference以及cplusplus中没有找到。
科学上网。使用Google搜索找到了想要的文档,网址如下:
https://pubs.opengroup.org/onlinepubs/007908799/xns/syssocket.h.html
其中找到了socket函数的详细用法如下:
补充:又发现一种更简单的查看socket函数的方法,直接在命令行输入 man 加函数名即可
1、复制内核工具链到家目录R:\sogou\toolchain
rootroot@rootroot-E400:~$
rootroot@rootroot-E400:~$ cd wyb/r16_tinav2.1/
rootroot@rootroot-E400:~/wyb/r16_tinav2.1$ cd prebuilt/gcc/
linux
-x86/arm/toolchain-sunxi/
rootroot@rootroot-E400:~/wyb/r16_tinav2.1/prebuilt/gcc/
linux
-x86/arm/toolchain-sunxi$ cp toolchain/ ~/sogou/ -r
rootroot@rootroot-E400:~/wyb/r16_tinav2.1/prebuilt/gcc/
linux
-x86/arm/toolchain-sunxi$ tar zcvf toolchain.tar.gz toolchain/
rootroot@rootroot-E400:~/wyb/r16_tinav2.1/prebuilt/gcc/
linux
-x86/arm/toolchain-sunxi$ cp toolchain.tar.gz ~/sogou/
rootroot@rootroot-E400:~/wyb/r16_tinav2.1/prebuilt/gcc/
linux
-x86/arm/toolchain-sunxi$ cd ~/sogou/
rootroot@rootroot-E400:~/sogou$ tar zxvf toolchain.tar.gz
2、添加环境变量,在/etc/profile最后一行添加如下一句(需要root权限):
export PATH="$PATH:/home/rootroot/sogou/toolchain/bin"
export STAGING_DIR="$PATH:/home/rootroot/sogou/toolchain"
.bashrc的最后输入:
export PATH="$PATH:/home/rootroot/sogou/toolchain/bin"
export STAGING_DIR="$PATH:/home/rootroot/sogou/toolchain"
3、输入arm-openwrt-
linux
-gcc -v检查是否可用(确认环境变量是否配置正确)
rootroot@rootroot-E400:~/sogou$ arm-openwrt-
linux
-gcc -v
Reading specs from /home/rootroot/sogou/toolchain/bin/../lib/gcc/arm-openwrt-
linux
-muslgnueabi/5.2.0/specs
COLLECT_GCC=arm-openwrt-
linux
-muslgnueabi-gcc.bin
COLLECT_LTO_WRAPPER=/home/rootroot/sogou/toolchain/bin/../libexec/gcc/arm-openwrt-
linux
-muslgnueabi/5.2.0/lto-wrapper
Target: arm-openwrt-
linux
-muslgnueabi
Configured with: /home/caiyongheng/tina_test/out/azalea-perf3/compile_dir/toolchain/gcc-5.2.0/configure --with-bugurl=https://dev.openwrt.org/ --with-pkgversion='OpenWrt GCC 5.2.0 70-1-1' --prefix=/home/caiyongheng/tina_test/out/azalea-perf3/staging_dir/toolchain --build=x86_64-
linux
-gnu --host=x86_64-
linux
-gnu --target=arm-openwrt-
linux
-muslgnueabi --with-gnu-ld --enable-target-optspace --disable-libgomp --disable-libmudflap --disable-multilib --disable-nls --without-isl --without-cloog --with-host-libstdcxx=-lstd
c++
--with-gmp=/home/caiyongheng/tina_test/out/host --with-mpfr=/home/caiyongheng/tina_test/out/host --with-mpc=/home/caiyongheng/tina_test/out/host --disable-decimal-float --with-diagnostics-color=auto-if-env --disable-libssp --enable-__cxa_atexit --with-arch=armv7-a --with-float=hard --with-headers=/home/caiyongheng/tina_test/out/azalea-perf3/staging_dir/toolchain/include --disable-libsanitizer --enable-languages=c,
c++
--enable-shared --enable-threads --with-slibdir=/home/caiyongheng/tina_test/out/azalea-perf3/staging_dir/toolchain/lib --enable-lto --with-libelf=/home/caiyongheng/tina_test/out/host
Thread model: posix
gcc version 5.2.0 (OpenWrt GCC 5.2.0 70-1-1)
rootroot@rootroot-E400:~/sogou$
4、创建工程目录record,在其中创建include、obj、lib、doc目录
5、所需的alsa头文件在R:\wyb\r16_tinav2.1\package\allwinner\liballwinner\LIBRARY\EXTERNAL\include\alsa,将其复制到工程目录中的include中
rootroot@rootroot-E400:~$ cd wyb/r16_tinav2.1/
rootroot@rootroot-E400:~/wyb/r16_tinav2.1$ cd package/allwinner/liballwinner/LIBRARY/EXTERNAL/include/
rootroot@rootroot-E400:~/wyb/r16_tinav2.1/package/allwinner/liballwinner/LIBRARY/EXTERNAL/include$ cp alsa/ ~/sogou/record/include/ -r
rootroot@rootroot-E400:~/wyb/r16_tinav2.1/package/allwinner/liballwinner/LIBRARY/EXTERNAL/include$
6、所需的so文件是R:\wyb\r16_tinav2.1\out\astar-parrot\staging_dir\target\usr\lib\libasound.so.2.0.0,将其复制到lib中,并改名为libasound.so
7、编辑record.c和Makefile
Makefile文件的内容:
CC=arm-openwrt-
linux
-g++
#CC=g++
DIR_OBJ=./obj
DIR_INCLUDE=./include
OBJ=record.o
record:$(OBJ)
$(CC) $(DIR_OBJ)/* -L./lib -lasound -o $@
%.o:%.c
$(CC) -c $< -I$(DIR_INCLUDE) -o $(DIR_OBJ)/$@
clean:
rm -f record $(DIR_OBJ)/*
make clean
rootroot@rootroot-E400:~/sogou/record$ make clean
rm -f record ./obj/*
rootroot@rootroot-E400:~/sogou/record$ make
arm-openwrt-
linux
-g++ -c record.c -I./include -o ./obj/record.o
In file included from ./include/alsa/asoundlib.h:32:0,
from record.c:13:
/home/rootroot/sogou/toolchain/include/
sys
/poll.h:1:2: warning: #warning redirecting incorrect #include <
sys
/poll.h> to <poll.h> [-Wcpp]
#warning redirecting incorrect #include <
sys
/poll.h> to <poll.h>
In file included from ./include/alsa/ctl_macros.h:13:0,
from ./include/alsa/control.h:54,
from ./include/alsa/asoundlib.h:47,
from record.c:13:
/home/rootroot/sogou/toolchain/include/
sys
/poll.h:1:2: warning: #warning redirecting incorrect #include <
sys
/poll.h> to <poll.h> [-Wcpp]
#warning redirecting incorrect #include <
sys
/poll.h> to <poll.h>
In file included from ./include/alsa/pcm_macros.h:13:0,
from ./include/alsa/pcm.h:116,
from ./include/alsa/asoundlib.h:48,
from record.c:13:
/home/rootroot/sogou/toolchain/include/
sys
/poll.h:1:2: warning: #warning redirecting incorrect #include <
sys
/poll.h> to <poll.h> [-Wcpp]
#warning redirecting incorrect #include <
sys
/poll.h> to <poll.h>
In file included from ./include/alsa/hctl_macros.h:13:0,
from ./include/alsa/hcontrol.h:36,
from ./include/alsa/mixer.h:25,
from ./include/alsa/asoundlib.h:49,
from record.c:13:
/home/rootroot/sogou/toolchain/include/
sys
/poll.h:1:2: warning: #warning redirecting incorrect #include <
sys
/poll.h> to <poll.h> [-Wcpp]
#warning redirecting incorrect #include <
sys
/poll.h> to <poll.h>
In file included from ./include/alsa/mixer_macros.h:13:0,
from ./include/alsa/mixer.h:72,
from ./include/alsa/asoundlib.h:49,
from record.c:13:
/home/rootroot/sogou/toolchain/include/
sys
/poll.h:1:2: warning: #warning redirecting incorrect #include <
sys
/poll.h> to <poll.h> [-Wcpp]
#warning redirecting incorrect #include <
sys
/poll.h> to <poll.h>
In file included from record.c:17:0:
/home/rootroot/sogou/toolchain/include/
sys
/poll.h:1:2: warning: #warning redirecting incorrect #include <
sys
/poll.h> to <poll.h> [-Wcpp]
#warning redirecting incorrect #include <
sys
/poll.h> to <poll.h>
arm-openwrt-
linux
-g++ ./obj/* -L./lib -lasound -o record
rootroot@rootroot-E400:~/sogou/record$
套接字(
socket
)是
Linux
下的一种进程间通信机制(
socket
IPC),
socket
是应用层与 TCP/IP 协议通信的中间软件抽象层,它是一组接口,还是一个标准BSD
socket
,能在不同平台很方便移植
Socket
TCP/IP协议族包括运输层、网络层、链路层,而
socket
所在位置如图,
Socket
是应用层与TCP/IP协议族通信的中间软件抽象层。
前几天下载了一个OpenGL的源码参详,无耐编译不过,提示错误为:
error C1083: 无法打开包括文件:“gl\GLAux.h”: No such file or directory
原来是:#include 出错
====================================================
解决方法如下:
1:下载此资源包
2:【glaux.dll】 复制到 C:\Windows\
sys
tem32
3:【glaux.lib】 复制到 C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib
4:【glaux.h】 复制到 C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\GL
5:重新编译运行即可
添加
socket
头文件
sys
/
socket
.h时:
报无法打开源文件,
sys
/
socket
.h
将头文件:#include <
sys
/
socket
.h>,替换成:#include <winsock.h>,问题解决
vs出现 fatal error C1083: 无法打开包括文件: “
sys
/
socket
.h”: No such file …
发表于2014-10-19 22:41|来自51CTO网页网上找的,你随便看看吧,比较详细:1. 什么是TCP/IP、UDP?2.
Socket
在哪里呢?3.
Socket
是什么呢?4. 你会使用它们吗?什么是TCP/IP、UDP?TCP/IP(Transmission Control Protocol/Internet Pro...
tcp和udp流程图,
socket
函数, bind函数,listen函数,accept函数,connect函数,recv、recvfrom、read函数,send、write、sendto、sendmsg函数,close、shutdown函数,htonl、ntohl、htons、ntohs本地主机和网络字节序转换,inet_addr、inet_aton、inet_ntop,IP地址转换,setsockopt函数和getsockopt函数,fcntl函数,getpeername与getsockname
#include ; #include ; int
socket
(int domain, int type, int protocol); domain 应该设置成 "AF_INET",
socket
有两个最重要的选项是 AF_UNIX 和 IAF_INET。AF_UNIX 就象 UNIX 路径名一样识别
socket
s。这种形式对于在同一台机器上的 IPC 很有用。而 AF_INET 使用象 192.9.200.10 这样被点号隔开的四个十进制数字
大部分公司的网络通信(比如服务器)程序都是部署在
linux
平台上的,但很多时候也是需要支持windows平台。本文讲述移植到windows的方法。下面是一个
linux
socket
通讯的简单例子
将其转换为windows平台下的代码如下:
简单来讲,就是得要:(1)注释掉
linux
下的头文件,添加windows下
socket
的头文件,比如#include
#include (2)增加别名:
(3)添加静态链接库:#pragma comment(l......
/* Create a new
socket
of type TYPE in domain DOMAIN, usingprotocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically.Returns a file descriptor for the new
socket
, or -1 for errors. */extern ...
/* Create a new
socket
of type TYPE in domain DOMAIN, using
protocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically.
Returns a file descriptor fo