mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-09-01 09:51:22 +02:00
gui/nfs: implement mac address lookup
Conflicts: src/gui/moviebrowser.cpp src/gui/nfs.cpp
This commit is contained in:
@@ -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