nps: poci/nws_poci.c - started work towards conversion from ifconf...
baggins
baggins at pld-linux.org
Fri Sep 9 18:37:49 CEST 2005
Author: baggins Date: Fri Sep 9 16:37:49 2005 GMT
Module: nps Tag: HEAD
---- Log message:
- started work towards conversion from ifconfig to iproute
- added functions for calculating prefix
---- Files affected:
nps/poci:
nws_poci.c (1.2 -> 1.3)
---- Diffs:
================================================================
Index: nps/poci/nws_poci.c
diff -u nps/poci/nws_poci.c:1.2 nps/poci/nws_poci.c:1.3
--- nps/poci/nws_poci.c:1.2 Mon Aug 1 23:24:24 2005
+++ nps/poci/nws_poci.c Fri Sep 9 18:37:44 2005
@@ -388,6 +388,34 @@
return;
}
+/*
+ * 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;
+
+ 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)
+{
+ return calc_minimal_prefix(nm, 0);
+}
/**********************************************
Function: getip
@@ -872,6 +900,7 @@
{
int fd;
int rc;
+ int pref;
struct in_addr inp;
unsigned long platIp, spIp;
char *drivername = JNET_DRIVERNAME;
@@ -902,7 +931,8 @@
close(fd);
inp.s_addr = ntohl(platIp);
- snprintf(command,BUFSIZE,"/sbin/ifconfig jnet0 %s",inet_ntoa(inp));
+ pref = calc_minimal_prefix(spIp, platIp);
+ snprintf(command,BUFSIZE,"/sbin/ip address flush jnet0 ; /sbin/ip address add %s/%d", inet_ntoa(inp), pref);
rc = system(command);
if(rc != 0) {
================================================================
---- CVS-web:
http://cvs.pld-linux.org/nps/poci/nws_poci.c?r1=1.2&r2=1.3&f=u
More information about the pld-cvs-commit
mailing list