提交 e043ee93 编写于 作者: C chegar

7190254: NetworkInterface getFlags implementation should support full integer...

7190254: NetworkInterface getFlags implementation should support full integer bit range for flags value
Reviewed-by: chegar
Contributed-by: NShirish Kuncolienkar <shirishk@linux.vnet.ibm.com>
上级 7bd1df28
......@@ -147,7 +147,7 @@ static struct sockaddr *getBroadcast(JNIEnv *env, int sock, const char *name, s
static short getSubnet(JNIEnv *env, int sock, const char *ifname);
static int getIndex(int sock, const char *ifname);
static int getFlags(int sock, const char *ifname);
static int getFlags(int sock, const char *ifname, int *flags);
static int getMacAddress(JNIEnv *env, int sock, const char* ifname, const struct in_addr* addr, unsigned char *buf);
static int getMTU(JNIEnv *env, int sock, const char *ifname);
......@@ -561,6 +561,7 @@ static int getFlags0(JNIEnv *env, jstring name) {
jboolean isCopy;
int ret, sock;
const char* name_utf;
int flags = 0;
name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
......@@ -571,7 +572,7 @@ static int getFlags0(JNIEnv *env, jstring name) {
name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
ret = getFlags(sock, name_utf);
ret = getFlags(sock, name_utf, &flags);
close(sock);
(*env)->ReleaseStringUTFChars(env, name, name_utf);
......@@ -581,7 +582,7 @@ static int getFlags0(JNIEnv *env, jstring name) {
return -1;
}
return ret;
return flags;
}
......@@ -852,6 +853,7 @@ netif *addif(JNIEnv *env, int sock, const char * if_name, netif *ifs, struct soc
int mask;
int isVirtual = 0;
int addr_size;
int flags = 0;
/*
* If the interface name is a logical interface then we
......@@ -906,7 +908,7 @@ netif *addif(JNIEnv *env, int sock, const char * if_name, netif *ifs, struct soc
* the 'parent' interface with the new records.
*/
*name_colonP = 0;
if (getFlags(sock, name) < 0) {
if (getFlags(sock, name, &flags) < 0 || flags < 0) {
// failed to access parent interface do not create parent.
// We are a virtual interface with no parent.
isVirtual = 1;
......@@ -1278,9 +1280,8 @@ static int getMTU(JNIEnv *env, int sock, const char *ifname) {
return if2.ifr_mtu;
}
static int getFlags(int sock, const char *ifname) {
static int getFlags(int sock, const char *ifname, int *flags) {
struct ifreq if2;
int ret = -1;
memset((char *) &if2, 0, sizeof(if2));
strcpy(if2.ifr_name, ifname);
......@@ -1289,7 +1290,12 @@ static int getFlags(int sock, const char *ifname) {
return -1;
}
return if2.ifr_flags;
if (sizeof(if2.ifr_flags) == sizeof(short)) {
*flags = (if2.ifr_flags & 0xffff);
} else {
*flags = if2.ifr_flags;
}
return 0;
}
#endif
......@@ -1663,7 +1669,7 @@ static int getMTU(JNIEnv *env, int sock, const char *ifname) {
}
static int getFlags(int sock, const char *ifname) {
static int getFlags(int sock, const char *ifname, int *flags) {
struct lifreq lifr;
memset((caddr_t)&lifr, 0, sizeof(lifr));
strcpy((caddr_t)&(lifr.lifr_name), ifname);
......@@ -1672,7 +1678,8 @@ static int getFlags(int sock, const char *ifname) {
return -1;
}
return lifr.lifr_flags;
*flags = lifr.lifr_flags;
return 0;
}
......@@ -1968,7 +1975,7 @@ static int getMTU(JNIEnv *env, int sock, const char *ifname) {
return if2.ifr_mtu;
}
static int getFlags(int sock, const char *ifname) {
static int getFlags(int sock, const char *ifname, int *flags) {
struct ifreq if2;
int ret = -1;
......@@ -1979,7 +1986,12 @@ static int getFlags(int sock, const char *ifname) {
return -1;
}
return (((int) if2.ifr_flags) & 0xffff);
if (sizeof(if2.ifr_flags) == sizeof(short)) {
*flags = (if2.ifr_flags & 0xffff);
} else {
*flags = if2.ifr_flags;
}
return 0;
}
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册