Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Java [игнор отключен] [закрыт для гостей] / A net IP retrieval / 5 сообщений из 5, страница 1 из 1
07.07.2007, 14:50:21
    #34645484
zeevik
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
A net IP retrieval
Hi,

Sorry for using English, but it's much faster (for me) . :)

I've written a Java application that runs on a Linux machine and communicates (via UDP) with the local (to its net) and remote (other nets) hosts.
A text file had to be created to contain these nets IPs for broadcasting(locally)/multicasting(remotely). As well some services were added, to access these IPs.
~zeev/nets.txt
--------
my_net 190.12.144
remote_net 222.12.150
...

I would prefer to use the same method that I'm using in C/C++, i.e '/etc/networks' configuration file and the 'getnetbyname()' service to retrieve the requested net's IP (instead of the method I've implemented in Java).
/etc/networks
-------------
127
my_net 190.12.144
remote_net 222.12.150
...

The problem is that I couldn't find the 'getnetbyname()' service under any Java package.

Is there a way to perform it properly ?

Sincerely

Zeev
...
Рейтинг: 0 / 0
09.07.2007, 11:05:08
    #34646751
Timm
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
A net IP retrieval
...
Рейтинг: 0 / 0
09.07.2007, 23:13:42
    #34648943
zeevik
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
A net IP retrieval
Thanks for the response.

But the java.net.InetAddress class handles only the '/etc/hosts' file - all the methods retrieve only the host oriented attributes: hostIp by name, hostName by IP, ... etc.
There are verification methods, such as isAnyLocalAddress(), isMulticastAddress(), ...,
but the provided services are dealing with the already retrieved IP address.
...
Рейтинг: 0 / 0
10.07.2007, 11:51:34
    #34649731
Timm
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
A net IP retrieval
Тогда давай описание сабрутины "getnetbyname". С примерами. Или ссылку на документацию.
ЗЫ. и забудь о конфигах *никсов. винда тоже ось.
...
Рейтинг: 0 / 0
10.07.2007, 22:46:22
    #34651819
zeevik
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
A net IP retrieval
http://linux.die.net/man/3/getnetbyname

авторgetnetbyname(3) - Linux man page
NAME
getnetent, getnetbyname, getnetbyaddr, setnetent, endnetent - get network entry
SYNOPSIS
#include <netdb.h>

struct netent *getnetent(void);

struct netent *getnetbyname(const char *name);

struct netent *getnetbyaddr(long net, int type);

void setnetent(int stayopen);

void endnetent(void);
DESCRIPTION
The getnetent() function reads the next line from the file /etc/networks and returns a structure netent containing the broken out fields from the line. The /etc/networks file is opened if necessary.
The getnetbyname() function returns a netent structure for the line from /etc/networks that matches the network name.

The getnetbyaddr() function returns a netent structure for the line that matches the network number net of type type.

The setnetent() function opens and rewinds the /etc/networks file. If stayopen is true (1), then the file will not be closed between calls to getnetbyname() and getnetbyaddr().

The endnetent() function closes /etc/networks.

The netent structure is defined in <netdb.h> as follows:

struct netent {
char *n_name; /* official network name */
char **n_aliases; /* alias list */
int n_addrtype; /* net address type */
unsigned long int n_net; /* network number */
}
The members of the netent structure are:

n_name
The official name of the network.
n_aliases
A zero terminated list of alternative names for the network.
n_addrtype
The type of the network number; always AF_INET.
n_net
The network number in host byte order.
RETURN VALUE
The getnetent(), getnetbyname() and getnetbyaddr() functions return the netent structure, or a NULL pointer if an error occurs or the end of the file is reached.
FILES
/etc/networks
networks database file
CONFORMING TO
4.3BSD, POSIX.1-2001.
SEE ALSO
getprotoent(3), getservent(3), networks(5) RFC 1101
REFERENCED BY
ipsec_atoaddr(3), ipsec_ttoaddr(3)
...
Рейтинг: 0 / 0
Форумы / Java [игнор отключен] [закрыт для гостей] / A net IP retrieval / 5 сообщений из 5, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]