[lwip-users] Setting the netif hostname without using DHCP

427 views
Skip to first unread message

Karthik Vadambacheri Manian

unread,
Jul 5, 2010, 4:55:08 PM7/5/10
to lwip-...@nongnu.org
Hi all,

I am trying to set the ip & hostname for a netif as below in
tcpip_thread() as below:


tcpip_thread()
{

................
................

rtl8139_netif = netif_find("ne0");
rtl8139_netif->ip_addr.addr = 0x0101a8c0;
rtl8139_netif->netmask.addr = 0x00ffffff;
rtl8139_netif->gw.addr = 0xfe01a881;
rtl8139_netif->hostname = "mylwip";
netif_set_default(rtl8139_netif);
netif_set_up(rtl8139_netif);

...................
...................
}

I am trying to use lwip in a lightweight kernel called kitten running
in a VM. When the VM comes up I could ping it using the statically
defined IP but not using hostname.
I checked on the lwip archive for previous discussions on this topic.
Few threads adviced to use the contrib/apps/netbios/netbios.c file.
They asked to set NETBIOS_LWIP_NAME to the host name and call
netbios_init().
I have set the NETBIOS_LWIP_NAME to the required hostname and called
netbios_init() after tcpip_init(). But still I could not ping using
hostname but I can ping using statically defined IP. Kindly let me
know what I am missing here?

Thanks,
karthik

_______________________________________________
lwip-users mailing list
lwip-...@nongnu.org
http://lists.nongnu.org/mailman/listinfo/lwip-users

gold...@gmx.de

unread,
Jul 6, 2010, 12:32:24 AM7/6/10
to Mailing list for lwIP users
Karthik Vadambacheri Manian wrote:
> I checked on the lwip archive for previous discussions on this topic.
> Few threads adviced to use the contrib/apps/netbios/netbios.c file.
> They asked to set NETBIOS_LWIP_NAME to the host name and call
> netbios_init().
> I have set the NETBIOS_LWIP_NAME to the required hostname and called
> netbios_init() after tcpip_init(). But still I could not ping using
> hostname but I can ping using statically defined IP. Kindly let me
> know what I am missing here?
First of all, the netbios name service only helps when you try to ping
*from* windows, not from any unix. If so, you might want to try to write
the name for NETBIOS_LWIP_NAME in uppercase, as the code uses strcmp and
windows sends the name uppercase, too.

Simon

Karthik Vadambacheri Manian

unread,
Jul 6, 2010, 11:50:37 AM7/6/10
to Mailing list for lwIP users
On Tue, Jul 6, 2010 at 12:32 AM, gold...@gmx.de <gold...@gmx.de> wrote:
> First of all, the netbios name service only helps when you try to ping
> *from* windows, not from any unix. If so, you might want to try to write the
> name for NETBIOS_LWIP_NAME in uppercase, as the code uses strcmp and windows
> sends the name uppercase, too.
>
Basically I want to ping from a unix box not a windows box. I tried
setting NETBIOS_LWIP_NAME but as you said it works for windows only.
So without using DHCP in LWIP is there a way to set the hostname which
I can ping from another m/c?

Thanks for your inputs Simon.

Regards,
karthik

gold...@gmx.de

unread,
Jul 6, 2010, 3:24:14 PM7/6/10
to Mailing list for lwIP users
Karthik Vadambacheri Manian wrote:
> Basically I want to ping from a unix box not a windows box. I tried
> setting NETBIOS_LWIP_NAME but as you said it works for windows only.
> So without using DHCP in LWIP is there a way to set the hostname which
> I can ping from another m/c?
The question isn't if there is a way in lwIP to set a hostname, the
question is how can you make your unix box know the name. And as far as
I know, the only portable way under unixes is DNS. You could configure
your local network's DNS server to translate names into addresses, but
that's not what you want, I guess. BTW, using DHCP for that also only
works if the DHCP- and DNS-server work together and are allowed (by the
admin) to take hostnames suggested by clients.

Another method would be mDNS, but that's not available yet for lwIP
(although there's a task for that on savannah, already) and you need
special software for unix, too.

Simon

David Empson

unread,
Jul 6, 2010, 7:30:39 PM7/6/10
to Mailing list for lwIP users
Simon Goldschmidt <gold...@gmx.de> wrote:
> Karthik Vadambacheri Manian wrote:
>> Basically I want to ping from a unix box not a windows box. I tried
>> setting NETBIOS_LWIP_NAME but as you said it works for windows only.
>> So without using DHCP in LWIP is there a way to set the hostname which
>> I can ping from another m/c?
> The question isn't if there is a way in lwIP to set a hostname, the
> question is how can you make your unix box know the name. And as far as I
> know, the only portable way under unixes is DNS. You could configure your
> local network's DNS server to translate names into addresses, but that's
> not what you want, I guess. BTW, using DHCP for that also only works if
> the DHCP- and DNS-server work together and are allowed (by the admin) to
> take hostnames suggested by clients.
>
> Another method would be mDNS, but that's not available yet for lwIP
> (although there's a task for that on savannah, already) and you need
> special software for unix, too.

If SAMBA is installed on the unix machine, you can use the 'nmblookup'
command to look up a NetBIOS name.

I don't know if later versions are any better, but the one I have (supplied
with Mac OS X 10.6, Samba version 3.0.28a-apple) doesn't have any options to
tidy up its output in a way which allows it to be easily used in conjunction
with
other commands, so you need to do some postprocessing with other tools.

Its normal output looks like this, if it finds the name on the first
available network interface:

% nmblookup foo
querying name on 192.168.0.255
192.168.0.17 foo<00>

If it can't find the name, it does this:

% nmblookup foo
querying name on 192.168.0.255
querying name on 172.16.191.255
name_query failed to find name foo


If you assume the name lookup will be successful, this trick can be used to
extract the IP address:

% nmblookup foo | tail -1 | sed 's/ .*//'
192.168.0.17

(tail -1 gets the last line, and sed with that argument strips off
everything on the line
beginning with the first space.)

If the name is not found, it returns

% nmblookup bar | tail -1 | sed 's/ .*//'
name_query

I'm sure a more seasoned unix shell scripter can turn this into an alias
with a parameter, or come up with a tidier way to extract the first "word"
from the last line of the output of nmblookup.

You can combine the command with another one by using backticks:

% ping `nmblookup foo | tail -1 | sed 's/ .*//'`
PING 192.168.0.17 (192.168.0.17): 56 data bytes
64 bytes from 192.168.0.17: icmp_seq=0 ttl=128 time=0.528 ms
64 bytes from 192.168.0.17: icmp_seq=1 ttl=128 time=0.598 ms
64 bytes from 192.168.0.17: icmp_seq=2 ttl=128 time=0.572 ms
^C
--- 192.168.0.17 ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.528/0.566/0.598/0.029 ms

(A failed lookup will attempt to ping 'name_query', which isn't likely to
achieve much.)

Karthik Vadambacheri Manian

unread,
Jul 7, 2010, 1:59:22 PM7/7/10
to Mailing list for lwIP users
Thanks a lot David & Simon for your insights.
Actually I cant use David's proposal because actually I would like to
ping between two kittens(Light Weight Kernels), which does not have
all the utilities as a traditional linux.
So I am thinking of using DHCP. By using DHCP I could register my
hostname and could ping from another VM. I need to set
LWIP_NETIF_HOSTNAME to achieve this.

Thanks,
Karthik

Reply all
Reply to author
Forward
0 new messages