coolsoul 1 жил өмнө
parent
commit
73e7b98082

+ 41 - 0
openwrt/devicediscover/Makefile

@@ -0,0 +1,41 @@
+#
+# Copyright (C) 2012 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=devicediscover
+PKG_RELEASE:=1
+
+PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/devicediscover
+  SECTION:=utils
+  CATEGORY:=Utilities
+  TITLE:=Frame buffer device testing tool
+  DEPENDS:=@DISPLAY_SUPPORT
+endef
+
+define Build/Configure
+endef
+
+define Build/Compile
+	$(MAKE) -C $(PKG_BUILD_DIR) \
+		CC="$(TARGET_CC)" \
+		CFLAGS="$(TARGET_CFLAGS) -Wall" \
+		LDFLAGS="$(TARGET_LDFLAGS)"
+endef
+
+define Package/devicediscover/install
+	$(INSTALL_DIR) $(1)/usr/sbin
+	$(INSTALL_DIR) $(1)//etc/init.d
+	$(INSTALL_BIN) ./files/devicediscover.init $(1)/etc/init.d/devicediscover
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/devicediscover $(1)/usr/sbin/
+endef
+
+$(eval $(call BuildPackage,devicediscover))

+ 17 - 0
openwrt/devicediscover/files/devicediscover.init

@@ -0,0 +1,17 @@
+#!/bin/sh /etc/rc.common
+
+START=94
+
+USE_PROCD=1
+PROG=/usr/sbin/devicediscover
+
+start_service() {
+	procd_open_instance
+	procd_set_param command $PROG --systemd
+	procd_set_param stderr 1
+	procd_close_instance
+}
+
+reload_service() {
+	procd_send_signal $PROG
+}

+ 14 - 0
openwrt/devicediscover/src/Makefile

@@ -0,0 +1,14 @@
+CC = gcc
+CFLAGS = -Wall
+OBJS = devicediscover.o
+
+all: devicediscover
+
+%.o: %.c
+	$(CC) $(CFLAGS) -c -o $@ $<
+
+devicediscover: $(OBJS)
+	$(CC) -o $@ $(OBJS)
+
+clean:
+	rm -f devicediscover *.o

+ 45 - 0
openwrt/devicediscover/src/devicediscover.c

@@ -0,0 +1,45 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <string.h>
+
+#define BUFFER_LENGTH 128
+
+int main(int argc, const char *argv[])
+{
+
+    int sockfd;
+    struct sockaddr_in broadcastaddr;
+    char buffer[BUFFER_LENGTH] = "restore machine";
+
+    if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+    {
+	printf("fail to socket\n");
+    }
+
+    broadcastaddr.sin_family = AF_INET;
+    broadcastaddr.sin_addr.s_addr = inet_addr("255.255.255.255");
+    broadcastaddr.sin_port = htons(8776);//WL
+
+    int optval = 1;
+
+    if(setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(int)) < 0)
+    {
+        printf("fail to setsockopt\n");
+	exit(-1);
+    }
+
+    while(1)
+    {
+        if(sendto(sockfd, buffer, strlen(buffer), 0, (struct sockaddr *)&broadcastaddr, sizeof(broadcastaddr)) < 0)
+        {
+            printf("error send broadcast message\n");
+        }
+	sleep(3);
+    }
+    return 0;
+}