nps: poci/jnetctl.c (NEW) - ioctl helper program

baggins baggins at pld-linux.org
Fri Sep 9 23:51:38 CEST 2005


Author: baggins                      Date: Fri Sep  9 21:51:35 2005 GMT
Module: nps                           Tag: HEAD
---- Log message:
- ioctl helper program

---- Files affected:
nps/poci:
   jnetctl.c (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: nps/poci/jnetctl.c
diff -u /dev/null nps/poci/jnetctl.c:1.1
--- /dev/null	Fri Sep  9 23:51:35 2005
+++ nps/poci/jnetctl.c	Fri Sep  9 23:51:30 2005
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * 
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  $Id$
+ ******************************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "jnet_shared.h"
+
+#define USAGE	"Usage: %s {set|get} [{platform|sp} [<IP adress>]]\n"
+
+int main(int argc, char *argv[])
+{
+    unsigned long platIp, spIp;
+    int fd;
+    struct in_addr inp;
+    uint32_t pip;
+
+    if (argc < 2) {
+	    fprintf(stderr, USAGE, argv[0]);
+	    return 1;
+    }
+
+    fd = open(JNET_DRIVERNAME, O_RDWR);
+    if (fd < 0) {
+        fprintf(stderr, "Failed to open the driver %s\n", JNET_DRIVERNAME);
+        return 2;
+    }
+
+    if (strcmp(argv[1], "get") == 0) {
+    	if (strcmp(argv[2], "platform") == 0) {
+		if (ioctl(fd, GET_PLAT_IP, &platIp) < 0) {
+			fprintf(stderr, "IOCTL_GET_PLAT_IP failed\n");
+			close(fd);
+			return 3;
+		}
+		inp.s_addr = ntohl(platIp);
+    		printf("Platform IP: %s\n", inet_ntoa(inp));
+	} else if (strcmp(argv[2], "sp") == 0) {
+		if (ioctl(fd, GET_SP_IP, &spIp) < 0) {
+			fprintf(stderr, "IOCTL_GET_SP_IP failed\n");
+			close(fd);
+			return 3;
+		}
+		inp.s_addr = ntohl(spIp);
+    		printf("SP IP: %s\n", inet_ntoa(inp));
+	} else {
+		fprintf(stderr, USAGE, argv[0]);
+		close(fd);
+		return 1;
+	}
+    } else if (strcmp(argv[1], "set") == 0) {
+    	if (strcmp(argv[2], "platform") == 0) {
+		if( inet_aton((const char *)argv[3], &inp) != 0) {
+			pip = ntohl(inp.s_addr);
+		} else {
+			fprintf(stderr, USAGE, argv[0]);
+			close(fd);
+			return 1;
+		}
+		if (ioctl(fd, SET_PLAT_IP, pip) < 0) {
+			fprintf(stderr, "IOCTL_SET_PLAT_IP failed\n");
+			return 3;
+		}
+	} else if (strcmp(argv[2], "sp") == 0) {
+		if( inet_aton((const char *)argv[3], &inp) != 0) {
+			pip = ntohl(inp.s_addr);
+		} else {
+			fprintf(stderr, USAGE, argv[0]);
+			close(fd);
+			return 1;
+		}
+		if (ioctl(fd, SET_SP_IP, pip) < 0) {
+			fprintf(stderr, "IOCTL_SET_SP_IP failed\n");
+			return 3;
+		}
+	} else {
+		fprintf(stderr, USAGE, argv[0]);
+		close(fd);
+		return 1;
+	}
+    } else {
+	    fprintf(stderr, USAGE, argv[0]);
+	    close(fd);
+	    return 1;
+    }
+
+    close(fd);
+    return 0;
+}
================================================================



More information about the pld-cvs-commit mailing list