summaryrefslogtreecommitdiffstats
path: root/upstream/archlinux/man7/unix.7
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-17 10:51:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-17 10:51:52 +0000
commit4ad94864781f48b1a4b77f9cfb934622bf756ba1 (patch)
tree3900955c1886e6d2570fea7125ee1f01bafe876d /upstream/archlinux/man7/unix.7
parentAdding upstream version 4.22.0. (diff)
downloadmanpages-l10n-4ad94864781f48b1a4b77f9cfb934622bf756ba1.tar.xz
manpages-l10n-4ad94864781f48b1a4b77f9cfb934622bf756ba1.zip
Adding upstream version 4.23.0.upstream/4.23.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'upstream/archlinux/man7/unix.7')
-rw-r--r--upstream/archlinux/man7/unix.781
1 files changed, 52 insertions, 29 deletions
diff --git a/upstream/archlinux/man7/unix.7 b/upstream/archlinux/man7/unix.7
index a583ad3d..42f1e27d 100644
--- a/upstream/archlinux/man7/unix.7
+++ b/upstream/archlinux/man7/unix.7
@@ -12,7 +12,7 @@
.\" address that can appear in the sockaddr_un structure: pathname,
.\" unnamed, and abstract.
.\"
-.TH UNIX 7 2023-12-21 "Linux man-pages 6.06"
+.TH UNIX 7 2024-05-02 "Linux man-pages 6.8"
.SH NAME
unix \- sockets for local interprocess communication
.SH SYNOPSIS
@@ -72,7 +72,7 @@ On Linux,
.I sun_path
is 108 bytes in size; see also BUGS, below.
.P
-Various systems calls (for example,
+Various system calls (for example,
.BR bind (2),
.BR connect (2),
and
@@ -833,7 +833,7 @@ UNIX domain stream sockets do not support the notion of out-of-band data.
.\"
.SH BUGS
When binding a socket to an address,
-Linux is one of the implementations that appends a null terminator
+Linux is one of the implementations that append a null terminator
if none is supplied in
.IR sun_path .
In most cases this is unproblematic:
@@ -955,14 +955,23 @@ $
.in
.SS Program source
\&
+.\" SRC BEGIN (connection.h)
.EX
/*
* File connection.h
*/
+#ifndef CONNECTION_H
+#define CONNECTION_H
\&
#define SOCKET_NAME "/tmp/9Lq7BNBnBycd6nxy.socket"
#define BUFFER_SIZE 12
\&
+#endif // include guard
+.EE
+.\" SRC END
+.P
+.\" SRC BEGIN (server.c)
+.EX
/*
* File server.c
*/
@@ -971,20 +980,23 @@ $
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
+#include <sys/types.h>
#include <sys/un.h>
#include <unistd.h>
+\&
#include "connection.h"
\&
int
-main(int argc, char *argv[])
+main(void)
{
- struct sockaddr_un name;
- int down_flag = 0;
- int ret;
- int connection_socket;
- int data_socket;
- int result;
- char buffer[BUFFER_SIZE];
+ int down_flag = 0;
+ int ret;
+ int connection_socket;
+ int data_socket;
+ int result;
+ ssize_t r, w;
+ struct sockaddr_un name;
+ char buffer[BUFFER_SIZE];
\&
/* Create local socket. */
\&
@@ -1043,8 +1055,8 @@ main(int argc, char *argv[])
\&
/* Wait for next data packet. */
\&
- ret = read(data_socket, buffer, sizeof(buffer));
- if (ret == \-1) {
+ r = read(data_socket, buffer, sizeof(buffer));
+ if (r == \-1) {
perror("read");
exit(EXIT_FAILURE);
}
@@ -1057,13 +1069,17 @@ main(int argc, char *argv[])
\&
if (!strncmp(buffer, "DOWN", sizeof(buffer))) {
down_flag = 1;
- break;
+ continue;
}
\&
if (!strncmp(buffer, "END", sizeof(buffer))) {
break;
}
\&
+ if (down_flag) {
+ continue;
+ }
+\&
/* Add received summand. */
\&
result += atoi(buffer);
@@ -1072,8 +1088,8 @@ main(int argc, char *argv[])
/* Send result. */
\&
sprintf(buffer, "%d", result);
- ret = write(data_socket, buffer, sizeof(buffer));
- if (ret == \-1) {
+ w = write(data_socket, buffer, sizeof(buffer));
+ if (w == \-1) {
perror("write");
exit(EXIT_FAILURE);
}
@@ -1097,27 +1113,33 @@ main(int argc, char *argv[])
\&
exit(EXIT_SUCCESS);
}
-\&
+.EE
+.\" SRC END
+.P
+.\" SRC BEGIN (client.c)
+.EX
/*
* File client.c
*/
\&
-#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
+#include <sys/types.h>
#include <sys/un.h>
#include <unistd.h>
+\&
#include "connection.h"
\&
int
main(int argc, char *argv[])
{
- struct sockaddr_un addr;
- int ret;
- int data_socket;
- char buffer[BUFFER_SIZE];
+ int ret;
+ int data_socket;
+ ssize_t r, w;
+ struct sockaddr_un addr;
+ char buffer[BUFFER_SIZE];
\&
/* Create local socket. */
\&
@@ -1149,9 +1171,9 @@ main(int argc, char *argv[])
\&
/* Send arguments. */
\&
- for (size_t i = 1; i < argc; ++i) {
- ret = write(data_socket, argv[i], strlen(argv[i]) + 1);
- if (ret == \-1) {
+ for (int i = 1; i < argc; ++i) {
+ w = write(data_socket, argv[i], strlen(argv[i]) + 1);
+ if (w == \-1) {
perror("write");
break;
}
@@ -1160,16 +1182,16 @@ main(int argc, char *argv[])
/* Request result. */
\&
strcpy(buffer, "END");
- ret = write(data_socket, buffer, strlen(buffer) + 1);
- if (ret == \-1) {
+ w = write(data_socket, buffer, strlen(buffer) + 1);
+ if (w == \-1) {
perror("write");
exit(EXIT_FAILURE);
}
\&
/* Receive result. */
\&
- ret = read(data_socket, buffer, sizeof(buffer));
- if (ret == \-1) {
+ r = read(data_socket, buffer, sizeof(buffer));
+ if (r == \-1) {
perror("read");
exit(EXIT_FAILURE);
}
@@ -1187,6 +1209,7 @@ main(int argc, char *argv[])
exit(EXIT_SUCCESS);
}
.EE
+.\" SRC END
.P
For examples of the use of
.BR SCM_RIGHTS ,