From 7b29a6153ea8aa358680afb0719a8159b2c1b147 Mon Sep 17 00:00:00 2001 From: Ralph Castain Date: Fri, 29 Apr 2011 17:56:15 +0000 Subject: [PATCH] Cover all the netmask values This commit was SVN r24665. --- opal/util/if.c | 103 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 96 insertions(+), 7 deletions(-) diff --git a/opal/util/if.c b/opal/util/if.c index cd0ad19d0a..ba8863f70b 100644 --- a/opal/util/if.c +++ b/opal/util/if.c @@ -534,13 +534,102 @@ opal_iftupletoaddr(char *inaddr, uint32_t *net, uint32_t *mask) * much of the addr to use: e.g., /16 */ pval = strtol(msk, NULL, 10); - if (24 == pval) { - *mask = 0xFFFFFF00; - } else if (16 == pval) { - *mask = 0xFFFF0000; - } else if (8 == pval) { - *mask = 0xFF000000; - } else { + switch(pval) { + case 30: + *mask = parse_dots("255.255.255.252"); + break; + case 29: + *mask = parse_dots("255.255.255.248"); + break; + case 28: + *mask = parse_dots("255.255.255.240"); + break; + case 27: + *mask = parse_dots("255.255.255.224"); + break; + case 26: + *mask = parse_dots("255.255.255.192"); + break; + case 25: + *mask = parse_dots("255.255.255.128"); + break; + case 24: + break; + *mask = parse_dots("255.255.255.0"); + break; + case 23: + *mask = parse_dots("255.255.254.0"); + break; + case 22: + *mask = parse_dots("255.255.252.0"); + break; + case 21: + *mask = parse_dots("255.255.248.0"); + break; + case 20: + *mask = parse_dots("255.255.240.0"); + break; + case 19: + *mask = parse_dots("255.255.224.0"); + break; + case 18: + *mask = parse_dots("255.255.192.0"); + break; + case 17: + *mask = parse_dots("255.255.128.0"); + break; + case 16: + *mask = parse_dots("255.255.0.0"); + break; + case 15: + *mask = parse_dots("255.254.0.0"); + break; + case 14: + *mask = parse_dots("255.252.0.0"); + break; + case 13: + *mask = parse_dots("255.248.0.0"); + break; + case 12: + *mask = parse_dots("255.240.0.0"); + break; + case 11: + *mask = parse_dots("255.224.0.0"); + break; + case 10: + *mask = parse_dots("255.192.0.0"); + break; + case 9: + *mask = parse_dots("255.128.0.0"); + break; + case 8: + *mask = parse_dots("255.0.0.0"); + break; + case 7: + *mask = parse_dots("254.0.0.0"); + break; + case 6: + *mask = parse_dots("252.0.0.0"); + break; + case 5: + *mask = parse_dots("248.0.0.0"); + break; + case 4: + *mask = parse_dots("240.0.0.0"); + break; + case 3: + *mask = parse_dots("224.0.0.0"); + break; + case 2: + *mask = parse_dots("192.0.0.0"); + break; + case 1: + *mask = parse_dots("128.0.0.0"); + break; + case 0: + *mask = parse_dots("0.0.0.0"); + break; + default: opal_output(0, "opal_iftupletoaddr: unknown mask"); free(addr); return OPAL_ERROR;