mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-29 05:40:25 -04:00
Move snd_is_local() to socket.c
Move snd_is_local() to socket.c since it's used in control_shm, too.
This commit is contained in:
parent
d4dd7650f9
commit
79c3d0a1ef
2 changed files with 54 additions and 52 deletions
|
|
@ -778,57 +778,6 @@ int snd_pcm_shm_open(snd_pcm_t **pcmp, const char *name,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef DOC_HIDDEN
|
|
||||||
int snd_is_local(struct hostent *hent)
|
|
||||||
{
|
|
||||||
int s;
|
|
||||||
int err;
|
|
||||||
struct ifconf conf;
|
|
||||||
size_t numreqs = 10;
|
|
||||||
size_t i;
|
|
||||||
struct in_addr *haddr = (struct in_addr*) hent->h_addr_list[0];
|
|
||||||
|
|
||||||
s = socket(PF_INET, SOCK_STREAM, 0);
|
|
||||||
if (s < 0) {
|
|
||||||
SYSERR("socket failed");
|
|
||||||
return -errno;
|
|
||||||
}
|
|
||||||
|
|
||||||
conf.ifc_len = numreqs * sizeof(struct ifreq);
|
|
||||||
conf.ifc_buf = malloc((unsigned int) conf.ifc_len);
|
|
||||||
if (! conf.ifc_buf)
|
|
||||||
return -ENOMEM;
|
|
||||||
while (1) {
|
|
||||||
err = ioctl(s, SIOCGIFCONF, &conf);
|
|
||||||
if (err < 0) {
|
|
||||||
SYSERR("SIOCGIFCONF failed");
|
|
||||||
return -errno;
|
|
||||||
}
|
|
||||||
if ((size_t)conf.ifc_len < numreqs * sizeof(struct ifreq))
|
|
||||||
break;
|
|
||||||
numreqs *= 2;
|
|
||||||
conf.ifc_len = numreqs * sizeof(struct ifreq);
|
|
||||||
conf.ifc_buf = realloc(conf.ifc_buf, (unsigned int) conf.ifc_len);
|
|
||||||
if (! conf.ifc_buf)
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
numreqs = conf.ifc_len / sizeof(struct ifreq);
|
|
||||||
for (i = 0; i < numreqs; ++i) {
|
|
||||||
struct ifreq *req = &conf.ifc_req[i];
|
|
||||||
struct sockaddr_in *s_in = (struct sockaddr_in *)&req->ifr_addr;
|
|
||||||
s_in->sin_family = AF_INET;
|
|
||||||
err = ioctl(s, SIOCGIFADDR, req);
|
|
||||||
if (err < 0)
|
|
||||||
continue;
|
|
||||||
if (haddr->s_addr == s_in->sin_addr.s_addr)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
close(s);
|
|
||||||
free(conf.ifc_buf);
|
|
||||||
return i < numreqs;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*! \page pcm_plugins
|
/*! \page pcm_plugins
|
||||||
|
|
||||||
\section pcm_plugins_shm Plugin: shm
|
\section pcm_plugins_shm Plugin: shm
|
||||||
|
|
|
||||||
55
src/socket.c
55
src/socket.c
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* \file pcm/socket.c
|
* \file socket.c
|
||||||
* \brief Socket helper routines
|
* \brief Socket helper routines
|
||||||
* \author Abramo Bagnara <abramo@alsa-project.org>
|
* \author Abramo Bagnara <abramo@alsa-project.org>
|
||||||
* \date 2003
|
* \date 2003
|
||||||
|
|
@ -33,6 +33,10 @@
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <netdb.h>
|
||||||
#include "local.h"
|
#include "local.h"
|
||||||
|
|
||||||
#ifndef DOC_HIDDEN
|
#ifndef DOC_HIDDEN
|
||||||
|
|
@ -102,4 +106,53 @@ int snd_receive_fd(int sock, void *data, size_t len, int *fd)
|
||||||
*fd = *fds;
|
*fd = *fds;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int snd_is_local(struct hostent *hent)
|
||||||
|
{
|
||||||
|
int s;
|
||||||
|
int err;
|
||||||
|
struct ifconf conf;
|
||||||
|
size_t numreqs = 10;
|
||||||
|
size_t i;
|
||||||
|
struct in_addr *haddr = (struct in_addr*) hent->h_addr_list[0];
|
||||||
|
|
||||||
|
s = socket(PF_INET, SOCK_STREAM, 0);
|
||||||
|
if (s < 0) {
|
||||||
|
SYSERR("socket failed");
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
conf.ifc_len = numreqs * sizeof(struct ifreq);
|
||||||
|
conf.ifc_buf = malloc((unsigned int) conf.ifc_len);
|
||||||
|
if (! conf.ifc_buf)
|
||||||
|
return -ENOMEM;
|
||||||
|
while (1) {
|
||||||
|
err = ioctl(s, SIOCGIFCONF, &conf);
|
||||||
|
if (err < 0) {
|
||||||
|
SYSERR("SIOCGIFCONF failed");
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
if ((size_t)conf.ifc_len < numreqs * sizeof(struct ifreq))
|
||||||
|
break;
|
||||||
|
numreqs *= 2;
|
||||||
|
conf.ifc_len = numreqs * sizeof(struct ifreq);
|
||||||
|
conf.ifc_buf = realloc(conf.ifc_buf, (unsigned int) conf.ifc_len);
|
||||||
|
if (! conf.ifc_buf)
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
numreqs = conf.ifc_len / sizeof(struct ifreq);
|
||||||
|
for (i = 0; i < numreqs; ++i) {
|
||||||
|
struct ifreq *req = &conf.ifc_req[i];
|
||||||
|
struct sockaddr_in *s_in = (struct sockaddr_in *)&req->ifr_addr;
|
||||||
|
s_in->sin_family = AF_INET;
|
||||||
|
err = ioctl(s, SIOCGIFADDR, req);
|
||||||
|
if (err < 0)
|
||||||
|
continue;
|
||||||
|
if (haddr->s_addr == s_in->sin_addr.s_addr)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
close(s);
|
||||||
|
free(conf.ifc_buf);
|
||||||
|
return i < numreqs;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue