For the bind problem of AF_UNIX Protocol Communication-general Linux technology-Linux technology and application information, see the following for details. An error is displayed in the last three rows. An error prompt is displayed, requesting help from ing...
PATH is the new path, no use
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Static void display_err (const char * on_what) // error output
{
Printf ("$ % s \ n", on_what );
Perror (on_what );
Exit (0 );
}
Int main (int argc, char * argv [])
{
Int error, on = 1, ret;
Int sock_UNIX; // socket
Struct sockaddr_un addr_UNIX; // AF_UNIX Protocol
Int len_UNIX; // AF_UNIX protocol length
Const char path [] = "/usr/unix/111"; // address?
Sock_UNIX = socket (AF_UNIX, SOCK_STREAM, 0 );
If (sock_UNIX =-1)
Display_err ("socket ()");
Unlink (path); // There are other purposes before the path. Clear the path connection.
Memset (& addr_UNIX, 0, sizeof (addr_UNIX); // apply for memory space
Addr_UNIX.sun_family = AF_LOCAL;
Strcpy (addr_UNIX.sun_path, path );
Len_UNIX = sizeof (struct sockaddr_un );
// Ret = setsockopt (sock_UNIX, SOL_SOCKET, SO_REUSEADDR, & on, sizeof (on ));
Error = bind (sock_UNIX, (struct sockaddr *) & addr_UNIX, len_UNIX); // bind socket sock_UNIX
//!!!!!!! Binding error. error message: Address already in use
Return 0;
}
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service