Skip to content

Commit c31984e

Browse files
committed
socket-util: Allow specifying socket type in vsock address
1 parent dbbf061 commit c31984e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/basic/socket-util.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,13 +1522,20 @@ int socket_address_parse_vsock(SocketAddress *ret_address, const char *s) {
15221522
_cleanup_free_ char *n = NULL;
15231523
char *e, *cid_start;
15241524
unsigned port, cid;
1525-
int r;
1525+
int type, r;
15261526

15271527
assert(ret_address);
15281528
assert(s);
15291529

1530-
cid_start = startswith(s, "vsock:");
1531-
if (!cid_start)
1530+
if ((cid_start = startswith(s, "vsock:")))
1531+
type = 0;
1532+
else if ((cid_start = startswith(s, "vsock-dgram:")))
1533+
type = SOCK_DGRAM;
1534+
else if ((cid_start = startswith(s, "vsock-seqpacket:")))
1535+
type = SOCK_SEQPACKET;
1536+
else if ((cid_start = startswith(s, "vsock-stream:")))
1537+
type = SOCK_STREAM;
1538+
else
15321539
return -EPROTO;
15331540

15341541
e = strchr(cid_start, ':');
@@ -1557,6 +1564,7 @@ int socket_address_parse_vsock(SocketAddress *ret_address, const char *s) {
15571564
.svm_family = AF_VSOCK,
15581565
.svm_port = port,
15591566
},
1567+
.type = type,
15601568
.size = sizeof(struct sockaddr_vm),
15611569
};
15621570

0 commit comments

Comments
 (0)