1 Sockets
- socket很像一个文件
- 本质上,socket是一个文件描述符指向网络设备而不是一个硬盘上的文件
int socket(int domain, int type, int protocol);
- domain is the addressing domain of socket
- HTTP traffic is over TCP, so that would be SOCK_STREAM. If we wanted to open a UDP socket, the keyword would be SOCK_DGRAM
- protocol is additional information about the protocol of the socket, but we will not need to use this option, so we’ll set it to 0.
- 成功返回文件描述符,失败返回-1.
2 Addressing
2.1 Glossary of Structures and Functions
3 Storing an IP address in struct in_addr
参考:
https://www.usna.edu/Users/cs/aviv/classes/ic221/s16/lec/26/lec.html#coderef-bad_ref