#define UNIX_PATH_MAX 108
struct sockaddr_un
{
__kernel_sa_family_t sun_family;
char sun_path[UNIX_PATH_MAX];
}
下面两个分别是服务端和客户端的示例源码
/**
* @name server.c
* @author IYATT-yx
* @brief 本地套接字TCP通信 - 服务器端
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <sys/un.h>
#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#define SERVER "/tmp/server.socket"
int main(void)
{
int lfd = socket(AF_LOCAL, SOCK_STREAM, 0);
if (lfd == -1)
{
perror("socket");
exit(EXIT_FAILURE);
}
unlink(SERVER);
struct sockaddr_un server;
server.sun_family = AF_LOCAL;
strcpy(server.sun_path, SERVER);
if (bind(lfd