nps: poci/nws_poci.c - finished ifconfig -> ip migration
baggins
baggins at pld-linux.org
Mon Sep 12 18:32:18 CEST 2005
Author: baggins Date: Mon Sep 12 16:32:17 2005 GMT
Module: nps Tag: HEAD
---- Log message:
- finished ifconfig -> ip migration
---- Files affected:
nps/poci:
nws_poci.c (1.7 -> 1.8)
---- Diffs:
================================================================
Index: nps/poci/nws_poci.c
diff -u nps/poci/nws_poci.c:1.7 nps/poci/nws_poci.c:1.8
--- nps/poci/nws_poci.c:1.7 Mon Sep 12 17:20:24 2005
+++ nps/poci/nws_poci.c Mon Sep 12 18:32:12 2005
@@ -395,33 +395,32 @@
}
/*
- * Function: calc_minimal_prefix
- * Arguments: two ip addreses
- * Returns: prefix
- * Purpose: Calculate minimal prefix for two IP addreses
- */
-int calc_minimal_prefix(in_addr_t addr1, in_addr_t addr2)
-{
- 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++;
-
- return prefix;
-}
-
-/*
* Function: netmask_to_prefix
* Arguments: ip netmask
* Returns: prefix
* Purpose: Calculate prefix for a give netmask
*/
-int netmask_to_prefix(in_addr_t nm)
+int netmask_to_prefix(char *netmask)
{
- return calc_minimal_prefix(nm, 0);
+ int i = 0, prefix = 0, j;
+ char *token;
+ unsigned char c;
+
+ token = strtok(netmask, ".");
+ while ((token != NULL) && (i < 4)) {
+ i++;
+ c = atol(token);
+ for (j=0x80; j>0; j/=2) {
+ if ((c & j) != 0)
+ prefix++;
+ else
+ break;
+ }
+ if (prefix < i*8)
+ break;
+ token = strtok(NULL, ".");
+ }
+ return prefix;
}
/**********************************************
@@ -1280,12 +1279,12 @@
char *buf - contains: interface name, address, mask, and gateway
Returns: none. Actually, the XML output back to the user indicates an error
if trying to change jnet through this cmd. otherwise
- returns the output from ifconfig cmd.
+ returns the output from ip cmd.
Purpose: set the ip address of a network adapter
**********************************************************************/
void set_ip(char *outBuf, char *buf)
{
- int i,j,k, val;
+ int i,j,k, val, pref;
int fd;
char *token, param[MAX_PARAM][BUFSIZE];
char tokensep[] =" \t,";
@@ -1339,27 +1338,29 @@
//the appropriate fields
switch(i) {
case 2:
- snprintf(command,BUFSIZE,
- "/sbin/ifconfig %s %s 2>%s",
- param[1],param[2], logFileName);
+ snprintf(command,BUFSIZE,
+ "/sbin/ip address add %s dev %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);
+ pref = netmask_to_prefix(param[3]);
+ snprintf(command,BUFSIZE,
+ "/sbin/ip address add %s/%d dev %s 2>%s",
+ param[1],param[2],pref, 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);
+ pref = netmask_to_prefix(param[3]);
+ snprintf(command,BUFSIZE,
+ "/sbin/ip address add %s/%d dev %s 2>%s",
+ param[1],param[2],pref, logFileName);
fprintf(stderr, "4: %s\n", command);
break;
default:
- snprintf(command,BUFSIZE,
- "/sbin/ifconfig %s 2>%s",
- param[0], logFileName);
+ snprintf(command,BUFSIZE,
+ "/sbin/ip address show %s 2>%s",
+ param[0], logFileName);
fprintf(stderr, "def: %s\n", command);
break;
}
================================================================
---- CVS-web:
http://cvs.pld-linux.org/nps/poci/nws_poci.c?r1=1.7&r2=1.8&f=u
More information about the pld-cvs-commit
mailing list