Hi,
The guest is waiting a connect from the host and then tries to read what has been sent by
the host.
Both Guest and Host codes look like that :
main()
{
int sock, msgsock, rval;
struct sockaddr_un server;
char buf[1024];
sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
perror("opening stream socket");
exit(1);
}
server.sun_family = AF_UNIX;
strcpy(server.sun_path, NAME);
if (bind(sock, (struct sockaddr *) &server, sizeof(struct sockaddr_un))) {
perror("binding stream socket");
exit(1);
}
printf("Socket has name %s\n", server.sun_path);
listen(sock, 5);
for (;;) {
msgsock = accept(sock, 0, 0);
if (msgsock == -1)
perror("accept");
else do {
bzero(buf, sizeof(buf));
if ((rval = read(msgsock, buf, 1024)) < 0)
on the host side :
main(argc, argv)
....
sock = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0);
if (sock < 0) {
perror("opening stream socket");
return(1);
}
server.sun_family = AF_UNIX;
strcpy(server.sun_path, argv[1]);
if (connect(sock, (struct sockaddr *) &server, sizeof(struct sockaddr_un)) <
0) {
close(sock);
perror("connecting stream socket");
return(1);
}
if (write(sock, buffer, strlen(buffer)) < 0)
perror("writing on stream socket");
Even if the host is not opening or sending anything I got this "already in use"
error message.
Regards,
J.P.
-----Message d'origine-----
De : Martin Kletzander [mailto:mkletzan@redhat.com]
Envoyé : mercredi 4 novembre 2015 16:21
À : Jean-Pierre Ribeauville
Cc : libvirt-users(a)redhat.com
Objet : Re: [libvirt-users] Retrieving datas sent by host within the Guest
On Wed, Nov 04, 2015 at 02:38:43PM +0000, Jean-Pierre Ribeauville wrote:
Hi,
I' trying to read datas sent by my KVM host within the Guest.
Host send these datas trough a channel UNIX type , by using AF_UNIX socket stuff.
If i try to retrive the datas by using such type of thing in the Guest :
#define NAME "/dev/virtio-ports/agent"
sock = socket(AF_UNIX, SOCK_STREAM, 0);
12 if (sock < 0) {
13 perror("opening stream socket");
14 exit(1);
15 }
16 server.sun_family = AF_UNIX;
17 strcpy(server.sun_path, NAME);
18 if (bind(sock, (struct sockaddr *) &server, sizeof(struct sockaddr_un))) {
19 perror("binding stream socket");
20 exit(1);
21 }
I got ""binding stream socket Address already in use" when trying to
bind the socket .
shouldn't you conect() instead of bind() ? Of course, open() should write as well.
But If I use such kind of thing :
fd = open("/dev/virtio-ports/agent", O_RDWR | O_NONBLOCK);
ssize_t size = read(fd, &rcv_buffer, 100);
if(size >0) printf("Read length(%d) %s\n", size, rcv_buffer);
It works fine.
Is there any chance to be able to use socket stuff on Guest side or is there anything I
misunderstand?
Thanks for help.
J.P.
J.P. Ribeauville
P: +33.(0).1.47.17.20.49
.
Puteaux 3 Etage 5 Bureau 4
jpribeauville@axway.com<mailto:jpribeauville@axway.com>
http://www.axway.com<http://www.axway.com/>
P Pensez à l'environnement avant d'imprimer.
_______________________________________________
libvirt-users mailing list
libvirt-users(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvirt-users