git://git.onelab.eu
/
distributedratelimiting.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
65b76c5
)
Dont ignore non-routable ip addresses if theyre the only choice!
author
Kevin Webb
<kcwebb@ucsd.edu>
Thu, 28 Jan 2010 16:23:52 +0000
(16:23 +0000)
committer
Kevin Webb
<kcwebb@ucsd.edu>
Thu, 28 Jan 2010 16:23:52 +0000
(16:23 +0000)
drl/util.c
patch
|
blob
|
history
diff --git
a/drl/util.c
b/drl/util.c
index
4bf3d04
..
a99e27e
100644
(file)
--- a/
drl/util.c
+++ b/
drl/util.c
@@
-231,7
+231,7
@@
void map_insert(map_handle map, void *key, int keylen, void *value) {
* return the string.
*/
char* get_local_ip(){
* return the string.
*/
char* get_local_ip(){
- char *ip;
+ char *ip
, *localip
;
struct ifaddrs *ifa = NULL, *ifp = NULL;
struct sockaddr *addr;
uint32_t ho_addr;
struct ifaddrs *ifa = NULL, *ifp = NULL;
struct sockaddr *addr;
uint32_t ho_addr;
@@
-253,6
+253,7
@@
char* get_local_ip(){
#define STRINGSIZE 200
ip = (char *)malloc(STRINGSIZE);
#define STRINGSIZE 200
ip = (char *)malloc(STRINGSIZE);
+ localip = NULL;
for (ifa = ifp; ifa; ifa=ifa->ifa_next){
for (ifa = ifp; ifa; ifa=ifa->ifa_next){
@@
-279,20
+280,32
@@
char* get_local_ip(){
/* is it MSB first? */
/* is it MSB first? */
- if ( (addrbyte != 192) && (addrbyte != 172)
- && (addrbyte != 10) && (addrbyte != 127) ){
+ /* We don't want to choose the loopback. */
+ if (addrbyte == 127)
+ continue;
+
+ /* If there's a non-local address, use that. */
+ if ((addrbyte != 192) && (addrbyte != 172) && (addrbyte != 10)){
printlog(LOG_WARN, " Using ip: %s\n",ip);
freeifaddrs(ifp);
printlog(LOG_WARN, " Using ip: %s\n",ip);
freeifaddrs(ifp);
-#if 0
-
return (ifa->ifa_addr->sin_addr
);
-#else
+ if (localip != NULL) {
+
free(localip
);
+ }
return(ip); /* for now return the IP address */
return(ip); /* for now return the IP address */
-#endif
+ } else {
+ if (localip == NULL) {
+ localip = malloc(STRINGSIZE);
+ }
+ strncpy(localip, ip, STRINGSIZE);
}
}
freeifaddrs(ifp);
free(ip);
}
}
freeifaddrs(ifp);
free(ip);
- return(NULL);
+
+ if (localip != NULL)
+ return localip;
+ else
+ return(NULL);
}
static FILE *urandfd = NULL;
}
static FILE *urandfd = NULL;