mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-27 07:23:09 +02:00
gui/nfs: implement mac address lookup
Conflicts: src/gui/moviebrowser.cpp src/gui/nfs.cpp
This commit is contained in:
@@ -1698,6 +1698,7 @@ nfs.mountnow Jetzt mounten
|
||||
nfs.mountok Mount erfolgreich
|
||||
nfs.mounttimeout Mount-Fehler: Timeout
|
||||
nfs.password Passwort
|
||||
nfs.refresh_mac MAC-Adresse feststellen
|
||||
nfs.remount Verzeichnisse erneut mounten
|
||||
nfs.type Typ
|
||||
nfs.type_cifs CIFS
|
||||
|
@@ -1698,6 +1698,7 @@ nfs.mountnow mount now
|
||||
nfs.mountok mount successful
|
||||
nfs.mounttimeout mount error: timeout
|
||||
nfs.password password
|
||||
nfs.refresh_mac look up MAC address
|
||||
nfs.remount remount directories
|
||||
nfs.type type
|
||||
nfs.type_cifs CIFS
|
||||
|
@@ -121,7 +121,6 @@ void netGetIP(std::string &dev, std::string &ip, std::string &mask, std::string
|
||||
brdcast = std::string(tmp);
|
||||
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
#if 0
|
||||
//never used
|
||||
|
@@ -3089,7 +3089,7 @@ int CMovieBrowser::showMovieInfoMenu(MI_MOVIE_INFO* movie_info)
|
||||
return res;
|
||||
}
|
||||
|
||||
extern "C" int pinghost( const char *hostname );
|
||||
extern int pinghost (const std::string &hostname, std::string *ip = NULL);
|
||||
bool CMovieBrowser::showMenu(MI_MOVIE_INFO* /*movie_info*/)
|
||||
{
|
||||
/* first clear screen */
|
||||
@@ -4085,7 +4085,7 @@ void CDirMenu::updateDirState(void)
|
||||
printf("updateDirState: %d: state %d nfs %d\n", i, dirState[i], dirNfsMountNr[i]);
|
||||
if(dirNfsMountNr[i] != -1)
|
||||
{
|
||||
int retvalue = pinghost(g_settings.network_nfs[dirNfsMountNr[i]].ip.c_str());
|
||||
int retvalue = pinghost(g_settings.network_nfs[dirNfsMountNr[i]].ip);
|
||||
if (retvalue == 0)//LOCALE_PING_UNREACHABLE
|
||||
{
|
||||
dirOptionText[i]="Server, offline";
|
||||
|
@@ -58,7 +58,7 @@
|
||||
#include <libnet.h>
|
||||
#include <libiw/iwscan.h>
|
||||
|
||||
extern "C" int pinghost( const char *hostname );
|
||||
extern int pinghost (const std::string &hostname, std::string *ip = NULL);
|
||||
|
||||
CNetworkSetup::CNetworkSetup(bool wizard_mode)
|
||||
{
|
||||
@@ -702,7 +702,7 @@ void CNetworkSetup::showCurrentNetworkSettings()
|
||||
|
||||
const char * CNetworkSetup::mypinghost(std::string &host)
|
||||
{
|
||||
int retvalue = pinghost(host.c_str());
|
||||
int retvalue = pinghost(host);
|
||||
switch (retvalue)
|
||||
{
|
||||
case 1: return (g_Locale->getText(LOCALE_PING_OK));
|
||||
@@ -776,7 +776,7 @@ void CNetworkSetup::testNetworkSettings()
|
||||
text += (std::string)g_Locale->getText(LOCALE_NETWORKMENU_NAMESERVER) + ":\n";
|
||||
text += offset + our_nameserver + " " + mypinghost(our_nameserver) + "\n";
|
||||
//NTPserver
|
||||
if ( (pinghost(our_nameserver.c_str()) == 1) && g_settings.network_ntpenable && (g_settings.network_ntpserver != "") )
|
||||
if ( (pinghost(our_nameserver) == 1) && g_settings.network_ntpenable && (g_settings.network_ntpserver != "") )
|
||||
{
|
||||
text += std::string(g_Locale->getText(LOCALE_NETWORKMENU_NTPSERVER)) + ":\n";
|
||||
text += offset + g_settings.network_ntpserver + " " + mypinghost(g_settings.network_ntpserver) + "\n";
|
||||
@@ -784,7 +784,7 @@ void CNetworkSetup::testNetworkSettings()
|
||||
//Wiki
|
||||
text += wiki_URL + ":\n";
|
||||
text += offset + "via IP (" + wiki_IP + "): " + mypinghost(wiki_IP) + "\n";
|
||||
if (pinghost(our_nameserver.c_str()) == 1)
|
||||
if (pinghost(our_nameserver) == 1)
|
||||
{
|
||||
text += offset + "via DNS: " + mypinghost(wiki_URL) + "\n";
|
||||
//testsite (or defaultsite)
|
||||
|
@@ -45,6 +45,7 @@
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include <system/helpers.h>
|
||||
#include <global.h>
|
||||
|
||||
#include <errno.h>
|
||||
@@ -54,6 +55,8 @@
|
||||
#include <neutrino.h>
|
||||
#include <zapit/client/zapittools.h>
|
||||
|
||||
extern int pinghost (const std::string &hostname, std::string *ip = NULL);
|
||||
|
||||
CNFSMountGui::CNFSMountGui()
|
||||
{
|
||||
// FIXME #warning move probing from exec() to fsmounter
|
||||
@@ -134,6 +137,27 @@ int CNFSMountGui::exec( CMenuTarget* parent, const std::string & actionKey )
|
||||
ISO_8859_1_entry[i] = ZapitTools::UTF8_to_Latin1(m_entry[i].c_str());
|
||||
}
|
||||
}
|
||||
else if(actionKey.substr(0,10)=="refreshMAC")
|
||||
{
|
||||
int nr=atoi(actionKey.substr(10,1));
|
||||
std::string h;
|
||||
pinghost(g_settings.network_nfs[nr].ip, &h);
|
||||
if (!h.empty()) {
|
||||
FILE *arptable = fopen("/proc/net/arp", "r");
|
||||
if (arptable) {
|
||||
char line[120], ip[120], mac[120];
|
||||
while (fgets(line, sizeof(line), arptable)) {
|
||||
if (2 == sscanf(line, "%s %*s %*s %s %*[^\n]", ip, mac)) {
|
||||
if (!strcmp(ip, h.c_str())) {
|
||||
g_settings.network_nfs[nr].mac = std::string(mac);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(arptable);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(actionKey.substr(0,10)=="mountentry")
|
||||
{
|
||||
parent->hide();
|
||||
@@ -261,7 +285,9 @@ int CNFSMountGui::menuEntry(int nr)
|
||||
CMenuForwarder *password_fwd = new CMenuForwarder(LOCALE_NFS_PASSWORD, (type != (int)CFSMounter::NFS), NULL, &passInput);
|
||||
|
||||
CMACInput macInput(LOCALE_RECORDINGMENU_SERVER_MAC, &g_settings.network_nfs[nr].mac, LOCALE_IPSETUP_HINT_1, LOCALE_IPSETUP_HINT_2);
|
||||
CMenuForwarder * macInput_fwd = new CMenuForwarder(LOCALE_RECORDINGMENU_SERVER_MAC, true, g_settings.network_nfs[nr].mac, &macInput);
|
||||
CMenuForwarder *macInput_fwd = new CMenuForwarder(LOCALE_RECORDINGMENU_SERVER_MAC, true, g_settings.network_nfs[nr].mac, &macInput);
|
||||
|
||||
CMenuForwarder *refreshMAC_fwd = new CMenuForwarder(LOCALE_NFS_REFRESH_MAC, true, NULL, this, ("refreshMAC" + to_string(nr)).c_str(), CRCInput::RC_yellow, NEUTRINO_ICON_BUTTON_YELLOW);
|
||||
|
||||
CMenuForwarder *mountnow_fwd = new CMenuForwarder(LOCALE_NFS_MOUNTNOW, !(CFSMounter::isMounted(g_settings.network_nfs[nr].local_dir)), NULL, this, cmd);
|
||||
|
||||
@@ -280,6 +306,8 @@ int CNFSMountGui::menuEntry(int nr)
|
||||
mountMenuEntryW.addItem(username_fwd);
|
||||
mountMenuEntryW.addItem(password_fwd);
|
||||
mountMenuEntryW.addItem(macInput_fwd);
|
||||
mountMenuEntryW.addItem(refreshMAC_fwd);
|
||||
mountMenuEntryW.addItem(GenericMenuSeparatorLine);
|
||||
mountMenuEntryW.addItem(mountnow_fwd);
|
||||
|
||||
int ret = mountMenuEntryW.exec(this,"");
|
||||
|
@@ -1725,6 +1725,7 @@ typedef enum
|
||||
LOCALE_NFS_MOUNTOK,
|
||||
LOCALE_NFS_MOUNTTIMEOUT,
|
||||
LOCALE_NFS_PASSWORD,
|
||||
LOCALE_NFS_REFRESH_MAC,
|
||||
LOCALE_NFS_REMOUNT,
|
||||
LOCALE_NFS_TYPE,
|
||||
LOCALE_NFS_TYPE_CIFS,
|
||||
|
@@ -1725,6 +1725,7 @@ const char * locale_real_names[] =
|
||||
"nfs.mountok",
|
||||
"nfs.mounttimeout",
|
||||
"nfs.password",
|
||||
"nfs.refresh_mac",
|
||||
"nfs.remount",
|
||||
"nfs.type",
|
||||
"nfs.type_cifs",
|
||||
|
@@ -38,12 +38,12 @@
|
||||
#define MAXDATA (MAXPKT-HDRLEN-TIMLEN)
|
||||
#define DEF_TIMEOUT 5
|
||||
|
||||
int ident = 0;
|
||||
int timo = 2;
|
||||
int rrt;
|
||||
int sock;
|
||||
static int ident = 0;
|
||||
static int timo = 2;
|
||||
static int rrt;
|
||||
static int sock = -1;
|
||||
|
||||
int
|
||||
static int
|
||||
in_checksum( u_short *buf, int len )
|
||||
{
|
||||
register long sum = 0;
|
||||
@@ -97,7 +97,7 @@ send_ping( const char *host, struct sockaddr_in *taddr )
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(( sock = socket( AF_INET, SOCK_RAW, proto->p_proto )) < 0 ){
|
||||
if((sock < 0) && ( sock = socket( AF_INET, SOCK_RAW, proto->p_proto )) < 0 ){
|
||||
#ifdef DEBUG
|
||||
perror( "sock" );
|
||||
#endif/*DEBUG*/
|
||||
@@ -117,6 +117,7 @@ send_ping( const char *host, struct sockaddr_in *taddr )
|
||||
perror( "sock" );
|
||||
#endif/*DEBUG*/
|
||||
close( sock );
|
||||
sock = -1;
|
||||
return -2;
|
||||
}
|
||||
if( ss != len ){
|
||||
@@ -124,13 +125,14 @@ send_ping( const char *host, struct sockaddr_in *taddr )
|
||||
perror( "malformed packet" );
|
||||
#endif/*DEBUG*/
|
||||
close( sock );
|
||||
sock = -1;
|
||||
return -2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
recv_ping( struct sockaddr_in *taddr )
|
||||
{
|
||||
int len;
|
||||
@@ -188,7 +190,7 @@ recv_ping( struct sockaddr_in *taddr )
|
||||
* returns an int value for the difference
|
||||
* between now and starttime in milliseconds.
|
||||
*/
|
||||
int
|
||||
static int
|
||||
elapsed_time( struct timeval *starttime ){
|
||||
struct timeval *newtime;
|
||||
int elapsed;
|
||||
@@ -209,12 +211,15 @@ elapsed_time( struct timeval *starttime ){
|
||||
return( elapsed );
|
||||
}
|
||||
|
||||
int
|
||||
myping( const char *hostname, int t )
|
||||
static int
|
||||
myping(const std::string &hostname, int t, struct sockaddr_in *sa = NULL)
|
||||
{
|
||||
int err;
|
||||
struct sockaddr_in sa;
|
||||
struct sockaddr_in _sa;
|
||||
struct timeval mytime;
|
||||
|
||||
if (!sa)
|
||||
sa = &_sa;
|
||||
|
||||
ident = getpid() & 0xFFFF;
|
||||
|
||||
@@ -222,34 +227,42 @@ myping( const char *hostname, int t )
|
||||
else timo = t;
|
||||
|
||||
(void) gettimeofday( &mytime, (struct timezone *)NULL);
|
||||
if(( err = send_ping( hostname, &sa )) < 0 ){
|
||||
if(( err = send_ping( hostname.c_str(), sa )) < 0 ){
|
||||
return err;
|
||||
}
|
||||
do{
|
||||
if(( rrt = elapsed_time( &mytime )) > timo * 1000 ){
|
||||
close( sock );
|
||||
sock = -1;
|
||||
return 0;
|
||||
}
|
||||
} while( recv_ping( &sa ));
|
||||
} while( recv_ping(sa));
|
||||
close( sock );
|
||||
sock = -1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
pinghost( const char *hostname )
|
||||
pinghost(const std::string &hostname, std::string *ip)
|
||||
{
|
||||
return myping( hostname, 0 );
|
||||
struct sockaddr_in sa;
|
||||
int res = myping( hostname, 0, &sa);
|
||||
if (ip) {
|
||||
char *p = inet_ntoa(sa.sin_addr);
|
||||
*ip = p ? std::string(p) : "";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int
|
||||
pingthost( const char *hostname, int t )
|
||||
pingthost(const std::string &hostname, int t)
|
||||
{
|
||||
return myping( hostname, t );
|
||||
}
|
||||
|
||||
int
|
||||
tpinghost( const char *hostname )
|
||||
tpinghost(const std::string &hostname)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@@ -260,7 +273,7 @@ tpinghost( const char *hostname )
|
||||
}
|
||||
|
||||
int
|
||||
tpingthost( const char *hostname, int t )
|
||||
tpingthost(const std::string &hostname, int t )
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#define PING_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#include "ping-config.h"
|
||||
|
||||
@@ -74,13 +75,13 @@
|
||||
# include <netinet/ip_icmp.h>
|
||||
#endif /* defined(__linux__) */
|
||||
|
||||
int send_ping( const char *host, struct sockaddr_in *taddr );
|
||||
int recv_ping( struct sockaddr_in *taddr );
|
||||
//int send_ping( const char *host, struct sockaddr_in *taddr );
|
||||
//int recv_ping( struct sockaddr_in *taddr );
|
||||
|
||||
int pinghost ( const char *hostname );
|
||||
int pingthost ( const char *hostname, int t );
|
||||
int tpinghost ( const char *hostname );
|
||||
int tpingthost( const char *hostname, int t );
|
||||
int pinghost (const std::string &hostname, std::string *ip = NULL);
|
||||
int pingthost (const std::string &hostname, int t );
|
||||
int tpinghost (const std::string &hostname );
|
||||
int tpingthost(const std::string &hostname, int t );
|
||||
|
||||
|
||||
#endif/*PING_H*/
|
||||
|
Reference in New Issue
Block a user