Changeset 360
- Timestamp:
- 03/03/06 00:23:26 (3 years ago)
- Files:
-
- nepenthes/trunk/conf/nepenthes.conf.dist (modified) (1 diff)
- nepenthes/trunk/nepenthes-core/src/SocketManager.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
nepenthes/trunk/conf/nepenthes.conf.dist
r347 r360 116 116 use_rawsockets "0"; // unstable feature 117 117 bind_address "0.0.0.0"; 118 119 // specify "if:ethX" to get the ip from an interface at startup, 120 // only works on linux! 118 121 }; 119 122 nepenthes/trunk/nepenthes-core/src/SocketManager.cpp
r341 r360 5 5 * 6 6 * 7 * Copyright (C) 2005 Paul Baecher & Markus Koetter 7 * Copyright (C) 2005 Paul Baecher & Markus Koetter & Georg Wicherski 8 8 * 9 9 * This program is free software; you can redistribute it and/or … … 61 61 #include "Config.hpp" 62 62 63 #ifdef __linux__ // bind to interface on linux 64 #include <net/if.h> 65 #include <sys/types.h> 66 #include <sys/ioctl.h> 67 #include <sys/socket.h> 68 #include <netinet/in.h> 69 #include <arpa/inet.h> 70 #endif // end bind to if 71 63 72 using namespace nepenthes; 64 73 using namespace std; … … 117 126 118 127 try { 119 m_BindAddress = inet_addr(m_Nepenthes->getConfig()->getValString("nepenthes.socketmanager.bind_address")); 128 string bindAddressString = m_Nepenthes->getConfig()->getValString("nepenthes.socketmanager.bind_address"); 129 130 #ifdef __linux__ 131 if(bindAddressString.substr(0, 3) == string("if:")) 132 { 133 const char * interfaceName = bindAddressString.substr(3).c_str(); 134 int ifaceSocket = socket(AF_INET, SOCK_STREAM, 0); 135 struct ifreq interfaceRequest; 136 struct sockaddr_in addrInterface; 137 138 strncpy(interfaceRequest.ifr_name, interfaceName, IFNAMSIZ - 1); 139 140 if(ifaceSocket < 0 || ioctl(ifaceSocket, SIOCGIFADDR, &interfaceRequest) < 0) 141 { 142 logCrit("Failed to obtain address for interface %s: %s!\n", interfaceName, strerror(errno)); 143 } else 144 { 145 memcpy(&addrInterface, &(interfaceRequest.ifr_addr), sizeof(addrInterface)); 146 logInfo("Obtained address of interface %s: %s\n", interfaceName, inet_ntoa(addrInterface.sin_addr)); 147 m_BindAddress = addrInterface.sin_addr.s_addr; 148 149 close(ifaceSocket); 150 } 151 152 } else 153 #endif 154 { 155 m_BindAddress = inet_addr(bindAddressString.c_str()); 156 } 157 120 158 if (m_BindAddress != INADDR_ANY) 121 159 {
