зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1229633: hash interface names on Windows. r=ekr
--HG-- extra : rebase_source : e76fc7866c70242ba957bd2c84c42c2f4fc2f592
This commit is contained in:
Родитель
3b820ef6d3
Коммит
c69876f082
|
@ -44,11 +44,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#define MAXIFNAME IFNAMSIZ
|
||||
#else
|
||||
#define MAXIFNAME 16
|
||||
#endif
|
||||
/* Length of a string hex representation of a MD5 hash */
|
||||
#define MAXIFNAME 33
|
||||
|
||||
/* Generic transport address
|
||||
|
||||
|
|
|
@ -75,11 +75,14 @@ static char *RCSSTRING __UNUSED__="$Id: addrs.c,v 1.2 2008/04/28 18:21:30 ekr Ex
|
|||
|
||||
#include "stun.h"
|
||||
#include "addrs.h"
|
||||
#include "nr_crypto.h"
|
||||
#include "util.h"
|
||||
|
||||
#if defined(WIN32)
|
||||
|
||||
#define WIN32_MAX_NUM_INTERFACES 20
|
||||
|
||||
#define NR_MD5_HASH_LENGTH 16
|
||||
|
||||
#define _NR_MAX_KEY_LENGTH 256
|
||||
#define _NR_MAX_NAME_LENGTH 512
|
||||
|
@ -149,7 +152,8 @@ stun_get_win32_addrs(nr_local_addr addrs[], int maxaddrs, int *count)
|
|||
int r,_status;
|
||||
PIP_ADAPTER_ADDRESSES AdapterAddresses = NULL, tmpAddress = NULL;
|
||||
ULONG buflen;
|
||||
char munged_ifname[IFNAMSIZ];
|
||||
char bin_hashed_ifname[NR_MD5_HASH_LENGTH];
|
||||
char hex_hashed_ifname[MAXIFNAME];
|
||||
int n = 0;
|
||||
|
||||
*count = 0;
|
||||
|
@ -184,27 +188,21 @@ stun_get_win32_addrs(nr_local_addr addrs[], int maxaddrs, int *count)
|
|||
/* Loop through the adapters */
|
||||
|
||||
for (tmpAddress = AdapterAddresses; tmpAddress != NULL; tmpAddress = tmpAddress->Next) {
|
||||
char *c;
|
||||
|
||||
if (tmpAddress->OperStatus != IfOperStatusUp)
|
||||
continue;
|
||||
|
||||
snprintf(munged_ifname, IFNAMSIZ, "%S%c", tmpAddress->FriendlyName, 0);
|
||||
/* replace spaces with underscores */
|
||||
c = strchr(munged_ifname, ' ');
|
||||
while (c != NULL) {
|
||||
*c = '_';
|
||||
c = strchr(munged_ifname, ' ');
|
||||
}
|
||||
c = strchr(munged_ifname, '.');
|
||||
while (c != NULL) {
|
||||
*c = '+';
|
||||
c = strchr(munged_ifname, '.');
|
||||
}
|
||||
|
||||
if ((tmpAddress->IfIndex != 0) || (tmpAddress->Ipv6IfIndex != 0)) {
|
||||
IP_ADAPTER_UNICAST_ADDRESS *u = 0;
|
||||
|
||||
if(r=nr_crypto_md5((UCHAR *)tmpAddress->FriendlyName,
|
||||
wcslen(tmpAddress->FriendlyName) * sizeof(wchar_t),
|
||||
bin_hashed_ifname))
|
||||
ABORT(r);
|
||||
if(r=nr_bin2hex(bin_hashed_ifname, sizeof(bin_hashed_ifname),
|
||||
hex_hashed_ifname))
|
||||
ABORT(r);
|
||||
|
||||
for (u = tmpAddress->FirstUnicastAddress; u != 0; u = u->Next) {
|
||||
SOCKET_ADDRESS *sa_addr = &u->Address;
|
||||
|
||||
|
@ -214,11 +212,11 @@ stun_get_win32_addrs(nr_local_addr addrs[], int maxaddrs, int *count)
|
|||
ABORT(r);
|
||||
}
|
||||
else {
|
||||
r_log(NR_LOG_STUN, LOG_DEBUG, "Unrecognized sa_family for adapteraddress %s",munged_ifname);
|
||||
r_log(NR_LOG_STUN, LOG_DEBUG, "Unrecognized sa_family for address on adapter %lu", tmpAddress->IfIndex);
|
||||
continue;
|
||||
}
|
||||
|
||||
strlcpy(addrs[n].addr.ifname, munged_ifname, sizeof(addrs[n].addr.ifname));
|
||||
strlcpy(addrs[n].addr.ifname, hex_hashed_ifname, sizeof(addrs[n].addr.ifname));
|
||||
/* TODO: (Bug 895793) Getting interface properties for Windows */
|
||||
addrs[n].interface.type = NR_INTERFACE_TYPE_UNKNOWN;
|
||||
addrs[n].interface.estimated_speed = 0;
|
||||
|
|
|
@ -94,7 +94,6 @@ typedef SOCKET NR_SOCKET;
|
|||
|
||||
// Until we refine the Windows port....
|
||||
|
||||
#define IFNAMSIZ 256 /* big enough for FriendlyNames */
|
||||
#define in_addr_t UINT4
|
||||
|
||||
#ifndef strlcpy
|
||||
|
|
|
@ -572,8 +572,10 @@ NR_reg_make_registry(NR_registry parent, char *child, NR_registry out)
|
|||
if (*child == '.')
|
||||
ABORT(R_BAD_ARGS);
|
||||
|
||||
plen = strlen(parent);
|
||||
clen = strlen(child);
|
||||
if (!clen)
|
||||
ABORT(R_BAD_ARGS);
|
||||
plen = strlen(parent);
|
||||
if ((plen + clen + 2) > sizeof(NR_registry))
|
||||
ABORT(R_BAD_ARGS);
|
||||
|
||||
|
@ -592,8 +594,6 @@ NR_reg_make_registry(NR_registry parent, char *child, NR_registry out)
|
|||
if (isspace(*c) || *c == '.' || *c == '/' || ! isprint(*c))
|
||||
*c = '_';
|
||||
}
|
||||
if (i == 0 || child[i-1] == '.')
|
||||
ABORT(R_BAD_ARGS);
|
||||
|
||||
*c = '\0';
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче