Both getsockname and gethostname can obtain IP addresses, but there are other IP addresses:
Getsockname: gets the IP address related to a specific socket.
Gethostname: obtains all IP addresses of the local machine.
Let's take a look at their
These functions either return a local protocol address (GETSOCKNAME) that is associated with a socket, or return the address of a foreign protocol associated with a socket (getpeername).
#include
int getsockname (int sockfd,struct sockaddr*
For server side:Bind with the port as a wildcard: for the server, bind (0,IP), after calling the bind function, you can call GetSockName to get the local port number of the serverWith the IP address as the wildcard address bind, only after accept
Basic operation of Socket:
(1) socket () function:
(2) Bind () function:
(3) Listen (), connect () function;
(4) The Accept () function;
(5) The Send and receive functions in the socket:
(6) The Close () function:
(7) The socket function is called
Associating processes and ports is a very useful function. You can clearly know which programs are using which ports are helpful for trojan detection and removal. However, although we can use the task manager to browse the process list and use
1. In the simplest client/server program, a client is a process and only one connection is initiated, you only need to modify it to allow a client to initiate multiple connections and then use only one connection to send data.
First, let's get to
[UNIX Network Programming] basic TCP socket programming and unix Network Programming
The concurrent server described in this chapter is a single customer Process Model Implemented by fork.
The following is the socket function of the basic TCP client/
How can I obtain the IP address of a specified interface in C?
The description of winsocket is as follows:
5.1.6 getsockname ()Brief description:Obtain the local name of a set of interfaces.
# Include ;
Int Pascal far getsockname (socket S, struct
1 socket functionIn order to perform network I/O, the first thing a process must do is call the socket function, specifying the desired type of communication protocol#include int socket (intintint protocol);//返回:若成功则为非负描述符,若出错则为-1Where family
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.