1
0
Fork 0
mirror of https://repo.or.cz/socat.git synced 2025-07-08 21:36:34 +00:00

VSOCK: short alias names, env var with peer info

This commit is contained in:
Gerhard Rieger 2022-10-30 11:25:19 +01:00
parent cb03d2f075
commit 2882ac6976
6 changed files with 63 additions and 2 deletions

View file

@ -3,7 +3,7 @@
/* Author: Stefano Garzarella <sgarzare@redhat.com */
/* Published under the GNU General Public License V.2, see file COPYING */
/* this file contains the source for opening addresses of VSOCK socket type */
/* This file contains the source for opening addresses of VSOCK socket type */
#include "xiosysincludes.h"
@ -164,4 +164,32 @@ static int xioopen_vsock_listen(int argc, const char *argv[], struct opt *opts,
}
#endif /* WITH_LISTEN */
/* Returns information that can be used for constructing an environment
variable describing the socket address.
if idx is 0, this function writes "ADDR" into namebuff and the CID address
into valuebuff, and returns 1 (which means that one more info is there).
if idx is 1, it writes "PORT" into namebuff and the port number into
valuebuff, and returns 0 (no more info)
namelen and valuelen contain the max. allowed length of output chars in the
respective buffer.
on error this function returns -1.
*/
int
xiosetsockaddrenv_vsock(int idx, char *namebuff, size_t namelen,
char *valuebuff, size_t valuelen,
struct sockaddr_vm *sa, int ipproto) {
switch (idx) {
case 0:
strcpy(namebuff, "ADDR");
snprintf(valuebuff, valuelen, F_uint32_t, sa->svm_cid);
return 1;
case 1:
strcpy(namebuff, "PORT");
snprintf(valuebuff, valuelen, F_uint32_t, sa->svm_port);
return 0;
}
return -1;
}
#endif /* WITH_VSOCK */