summaryrefslogtreecommitdiffstats
path: root/avahi-core/socket.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-06-03 12:45:47 +0000
committerLennart Poettering <lennart@poettering.net>2005-06-03 12:45:47 +0000
commit4ff0807c04fcc239de52a793bceb88e7f3408f3f (patch)
treed91040a9cbf354d21d1379efb341a7d52282b681 /avahi-core/socket.c
parentf1b541eb614861312f917dab1bf75ad8267e321a (diff)
* implement reflection (including legacy unicast reflection)
* implement a history in the probe scheduler git-svn-id: file:///home/lennart/svn/public/avahi/trunk@92 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-core/socket.c')
-rw-r--r--avahi-core/socket.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/avahi-core/socket.c b/avahi-core/socket.c
index 2833d27..a2264ce 100644
--- a/avahi-core/socket.c
+++ b/avahi-core/socket.c
@@ -555,3 +555,98 @@ fail:
return NULL;
}
+gint avahi_open_legacy_unicast_socket_ipv4(void) {
+ struct sockaddr_in local;
+ int fd = -1, yes;
+
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ g_warning("socket() failed: %s\n", strerror(errno));
+ goto fail;
+ }
+
+ memset(&local, 0, sizeof(local));
+ local.sin_family = AF_INET;
+
+ if (bind(fd, (struct sockaddr*) &local, sizeof(local)) < 0) {
+ g_warning("bind() failed: %s\n", strerror(errno));
+ goto fail;
+ }
+
+ yes = 1;
+ if (setsockopt(fd, SOL_IP, IP_RECVTTL, &yes, sizeof(yes)) < 0) {
+ g_warning("IP_RECVTTL failed: %s\n", strerror(errno));
+ goto fail;
+ }
+
+ yes = 1;
+ if (setsockopt(fd, SOL_IP, IP_PKTINFO, &yes, sizeof(yes)) < 0) {
+ g_warning("IP_PKTINFO failed: %s\n", strerror(errno));
+ goto fail;
+ }
+
+ if (avahi_set_cloexec(fd) < 0) {
+ g_warning("FD_CLOEXEC failed: %s\n", strerror(errno));
+ goto fail;
+ }
+
+ if (avahi_set_nonblock(fd) < 0) {
+ g_warning("O_NONBLOCK failed: %s\n", strerror(errno));
+ goto fail;
+ }
+
+ return fd;
+
+fail:
+ if (fd >= 0)
+ close(fd);
+
+ return -1;
+}
+
+gint avahi_open_legacy_unicast_socket_ipv6(void) {
+ struct sockaddr_in local;
+ int fd = -1, yes;
+
+ if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
+ g_warning("socket() failed: %s\n", strerror(errno));
+ goto fail;
+ }
+
+ memset(&local, 0, sizeof(local));
+ local.sin_family = AF_INET;
+
+ if (bind(fd, (struct sockaddr*) &local, sizeof(local)) < 0) {
+ g_warning("bind() failed: %s\n", strerror(errno));
+ goto fail;
+ }
+
+ yes = 1;
+ if (setsockopt(fd, SOL_IPV6, IPV6_HOPLIMIT, &yes, sizeof(yes)) < 0) {
+ g_warning("IPV6_HOPLIMIT failed: %s\n", strerror(errno));
+ goto fail;
+ }
+
+ yes = 1;
+ if (setsockopt(fd, SOL_IPV6, IPV6_PKTINFO, &yes, sizeof(yes)) < 0) {
+ g_warning("IPV6_PKTINFO failed: %s\n", strerror(errno));
+ goto fail;
+ }
+
+ if (avahi_set_cloexec(fd) < 0) {
+ g_warning("FD_CLOEXEC failed: %s\n", strerror(errno));
+ goto fail;
+ }
+
+ if (avahi_set_nonblock(fd) < 0) {
+ g_warning("O_NONBLOCK failed: %s\n", strerror(errno));
+ goto fail;
+ }
+
+ return fd;
+
+fail:
+ if (fd >= 0)
+ close(fd);
+
+ return -1;
+}