From 216986e8481c81cd81a14138f5f7076c495bb2b4 Mon Sep 17 00:00:00 2001 From: OpenGnSys Support Team Date: Wed, 22 Dec 2021 16:38:29 +0100 Subject: #915 consolidate WoL sender function This patch aims simplifies the WoL sender routine. A few related changes: - Replace goto err to continue if IP address is malformed - Use ret |= instead of ret &= to accumulate error code. --- src/ogAdmServer.c | 76 ------------------------------------------------------- 1 file changed, 76 deletions(-) (limited to 'src/ogAdmServer.c') diff --git a/src/ogAdmServer.c b/src/ogAdmServer.c index 2b64254..8c6702f 100644 --- a/src/ogAdmServer.c +++ b/src/ogAdmServer.c @@ -271,82 +271,6 @@ int checkDato(struct og_dbi *dbi, char *dato, const char *tabla, return (identificador); } -enum wol_delivery_type { - OG_WOL_BROADCAST = 1, - OG_WOL_UNICAST = 2 -}; - -//_____________________________________________________________________________________________________________ -// Función: WakeUp -// -// Descripción: -// Enciende el ordenador cuya MAC se pasa como parámetro -// Parámetros: -// - s : Socket para enviar trama magic packet -// - iph : Cadena con la dirección ip -// - mac : Cadena con la dirección mac en formato XXXXXXXXXXXX -// - mar: Método de arranque (1=Broadcast, 2=Unicast) -// Devuelve: -// true: Si el proceso es correcto -// false: En caso de ocurrir algún error -//_____________________________________________________________________________________________________________ -// -bool WakeUp(int s, const char *iph, const char *mac, const char *netmask, const char *mar) -{ - struct in_addr addr, netmask_addr, broadcast_addr ={}; - unsigned int macaddr[OG_WOL_MACADDR_LEN]; - char HDaddress_bin[OG_WOL_MACADDR_LEN]; - struct sockaddr_in WakeUpCliente; - struct wol_msg Trama_WakeUp; - bool ret; - int i; - - if (!inet_aton(iph, &addr)) { - syslog(LOG_ERR, "bad IP address\n"); - return false; - } - - if (!inet_aton(netmask, &netmask_addr)) { - syslog(LOG_ERR, "bad netmask address: %s\n", netmask); - return false; - } - - broadcast_addr.s_addr = addr.s_addr | ~netmask_addr.s_addr; - - for (i = 0; i < 6; i++) // Primera secuencia de la trama Wake Up (0xFFFFFFFFFFFF) - Trama_WakeUp.secuencia_FF[i] = 0xFF; - - sscanf(mac, "%02x%02x%02x%02x%02x%02x", - &macaddr[0], &macaddr[1], &macaddr[2], - &macaddr[3], &macaddr[4], &macaddr[5]); - - for (i = 0; i < 6; i++) - HDaddress_bin[i] = (uint8_t)macaddr[i]; - - for (i = 0; i < 16; i++) // Segunda secuencia de la trama Wake Up , repetir 16 veces su la MAC - memcpy(&Trama_WakeUp.macbin[i][0], &HDaddress_bin, 6); - - /* Creación de socket del cliente que recibe la trama magic packet */ - WakeUpCliente.sin_family = AF_INET; - WakeUpCliente.sin_port = htons((short) PUERTO_WAKEUP); - - switch (atoi(mar)) { - case OG_WOL_BROADCAST: - ret = wake_up_broadcast(s, &WakeUpCliente, &Trama_WakeUp); - ret &= wake_up_send(s, &WakeUpCliente, &Trama_WakeUp, - &broadcast_addr); - break; - case OG_WOL_UNICAST: - ret = wake_up_send(s, &WakeUpCliente, &Trama_WakeUp, &addr); - break; - default: - syslog(LOG_ERR, "unknown wol type\n"); - ret = false; - break; - } - return ret; -} - // ________________________________________________________________________________________________________ // Función: actualizaCreacionImagen // -- cgit v1.2.3-18-g5258