nps: poci/nws_poci.c - more ifconfig -> iproute2 changes - WIP, lo...

baggins baggins at pld-linux.org
Sat Sep 10 01:16:17 CEST 2005


Author: baggins                      Date: Fri Sep  9 23:16:17 2005 GMT
Module: nps                           Tag: HEAD
---- Log message:
- more ifconfig -> iproute2 changes
- WIP, lotsa debig crap

---- Files affected:
nps/poci:
   nws_poci.c (1.4 -> 1.5) 

---- Diffs:

================================================================
Index: nps/poci/nws_poci.c
diff -u nps/poci/nws_poci.c:1.4 nps/poci/nws_poci.c:1.5
--- nps/poci/nws_poci.c:1.4	Fri Sep  9 18:40:01 2005
+++ nps/poci/nws_poci.c	Sat Sep 10 01:16:12 2005
@@ -87,11 +87,11 @@
 
     // prepare to write stuff to syslog, in case there is an error
     openlog("NWS_POCI", LOG_PERROR, LOG_DAEMON );
-
+/*
     if( daemon(0,0) != 0) {        //we run as a daemon
         syslog(LOG_INFO, "daemon call failed\n");
     }
-
+*/
     getPlatIp();        //causes firewall to be set, and jnet adapter to get
                         //the correct ip address as deemed by the sp
 
@@ -399,6 +399,7 @@
 	int prefix = 0;
 	in_addr_t x;
 
+fprintf(stderr, "%0x, %0x, %d\n", addr1, addr2, sizeof(addr1));
 	x=addr1 ^ addr2;
 	while (((x << prefix) & 0x80000000) == 0)
 		prefix++;
@@ -931,8 +932,9 @@
     close(fd);
 
     inp.s_addr = ntohl(platIp);
-    pref = calc_minimal_prefix(ntohl(spIp), ntohl(platIp));
-    snprintf(command,BUFSIZE,"/sbin/ip address flush jnet0 ; /sbin/ip address add %s/%d", inet_ntoa(inp), pref);
+fprintf(stderr, "%0x, %0x, %d\n", spIp, platIp, sizeof(spIp));
+    pref = calc_minimal_prefix(spIp, platIp);
+    snprintf(command,BUFSIZE,"/sbin/ip address flush jnet0 ; /sbin/ip address add %s/%d dev jnet0", inet_ntoa(inp), pref);
 
     rc = system(command);
     if(rc != 0) {
@@ -1330,21 +1332,25 @@
         snprintf(command,BUFSIZE,
             "/sbin/ifconfig %s %s 2>%s",
         param[1],param[2], logFileName);
+fprintf(stderr, "2: %s\n", command);
         break;
     case 3:
         snprintf(command,BUFSIZE,
             "/sbin/ifconfig %s %s netmask %s 2>%s",
         param[1],param[2],param[3], logFileName);
+fprintf(stderr, "3: %s\n", command);
         break;
     case 4:
         snprintf(command,BUFSIZE,
             "/sbin/ifconfig %s %s netmask %s 2>%s",
         param[1],param[2],param[3], logFileName);
+fprintf(stderr, "4: %s\n", command);
         break;
     default:
         snprintf(command,BUFSIZE,
             "/sbin/ifconfig %s 2>%s",
         param[0], logFileName);
+fprintf(stderr, "def: %s\n", command);
         break;
     }
     cleanse(command);   //remove non alpha-numeric text
@@ -1650,20 +1656,33 @@
     int fd;
     uint32_t pip;
     struct in_addr inp;
+    int pref;
 
     printStart(outBuf);
 
     //tasks.
     //1.  edit start-up script to change platform ip addr.
+fprintf(stderr, "buf: %s\n", buf);
 
     //first, filter out the IP addresses from the incoming
     //parameters.
     token = strstr(buf,"p=");
     platIp = (unsigned char *)(token+2);
+
     token = strstr(buf,"s=");
     spIp = (unsigned char *)(token+2);
+
+    token = platIp;
+    while (isdigit(*token) || (*token == '.')) token++;
     *token = '\0';
 
+    token = spIp;
+    while (isdigit(*token) || (*token == '.')) token++;
+    *token = '\0';
+    
+fprintf(stderr, "platIp: %s\n", platIp);
+fprintf(stderr, "spIp: %s\n", spIp);
+
     if(strlen((char *)platIp) < 3 || strlen((char *)spIp) < 3) {
         snprintf(command,BUFSIZE,
             "<error>Invalid ip addresses plat = %s, sp = %s</error>"
@@ -1692,8 +1711,11 @@
         }
 
         //now bring restart the network at this new address.
-        snprintf(command,BUFSIZE,
-            "/sbin/ifconfig jnet0 down; ifconfig jnet0 %s",platIp);
+	pref = calc_minimal_prefix(inet_network(spIp), inet_network(platIp));
+	snprintf(command,BUFSIZE,"/sbin/ip address flush jnet0 ;"
+				 "/sbin/ip address add %s/%d dev jnet0",
+				 platIp, pref);
+fprintf(stderr, "set: %s\n", command);
         if( system(command) != 0) {
             syslog(LOG_CRIT, "Jnet set ip failed\n");
             //Even though the change may have failed, we will return
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/nps/poci/nws_poci.c?r1=1.4&r2=1.5&f=u




More information about the pld-cvs-commit mailing list