summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ogAdmServer.c24
-rw-r--r--src/wol.c20
-rw-r--r--src/wol.h1
3 files changed, 25 insertions, 20 deletions
diff --git a/src/ogAdmServer.c b/src/ogAdmServer.c
index 3ba5b30..90dd0c8 100644
--- a/src/ogAdmServer.c
+++ b/src/ogAdmServer.c
@@ -455,27 +455,11 @@ int checkDato(struct og_dbi *dbi, char *dato, const char *tabla,
bool Levanta(char *ptrIP[], char *ptrMacs[], char *ptrNetmasks[], int lon,
char *mar)
{
- unsigned int on = 1;
- struct sockaddr_in local;
- int i, res;
- int s;
-
- /* Creación de socket para envío de magig packet */
- s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
- if (s < 0) {
- syslog(LOG_ERR, "cannot create socket for magic packet\n");
- return false;
- }
- res = setsockopt(s, SOL_SOCKET, SO_BROADCAST, (unsigned int *) &on,
- sizeof(on));
- if (res < 0) {
- syslog(LOG_ERR, "cannot set broadcast socket\n");
+ int i, s;
+
+ s = wol_socket_open();
+ if (s < 0)
return false;
- }
- memset(&local, 0, sizeof(local));
- local.sin_family = AF_INET;
- local.sin_port = htons(PUERTO_WAKEUP);
- local.sin_addr.s_addr = htonl(INADDR_ANY);
for (i = 0; i < lon; i++) {
if (!WakeUp(s, ptrIP[i], ptrMacs[i], ptrNetmasks[i], mar)) {
diff --git a/src/wol.c b/src/wol.c
index 79bfaa3..40a390c 100644
--- a/src/wol.c
+++ b/src/wol.c
@@ -20,6 +20,26 @@
#include "wol.h"
#include "ogAdmServer.h"
+int wol_socket_open(void)
+{
+ unsigned int on = 1;
+ int ret, s;
+
+ s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (s < 0) {
+ syslog(LOG_ERR, "cannot create socket for magic packet\n");
+ return -1;
+ }
+ ret = setsockopt(s, SOL_SOCKET, SO_BROADCAST, (unsigned int *) &on,
+ sizeof(on));
+ if (ret < 0) {
+ syslog(LOG_ERR, "cannot set broadcast socket\n");
+ return -1;
+ }
+
+ return s;
+}
+
bool wake_up_send(int sd, struct sockaddr_in *client,
const struct wol_msg *msg, const struct in_addr *addr)
{
diff --git a/src/wol.h b/src/wol.h
index c15cf3a..8682520 100644
--- a/src/wol.h
+++ b/src/wol.h
@@ -12,6 +12,7 @@ struct wol_msg {
char macbin[OG_WOL_REPEAT][OG_WOL_MACADDR_LEN];
};
+int wol_socket_open(void);
bool wake_up_send(int sd, struct sockaddr_in *client,
const struct wol_msg *msg, const struct in_addr *addr);
bool wake_up_broadcast(int sd, struct sockaddr_in *client,