File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes Writing DHCP client/server in JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Writing DHCP client/server in JAVA" Watch "Writing DHCP client/server in JAVA" New topic

Writing DHCP client/server in JAVA

KaKa Ng

Joined: Sep 21, 2003
Posts: 1
I would like to bulid something that has DHCP functionality. However, I found the API of java are all on top of layer 3. Whenever it creates a socket, it binds to an IP and a port. In such case, how can I implement DHCP (if without native code?) Any idea?
In particular in client side,
I design a DHCPMessage class to represent DHCP packet
I send a DHCP Discover message to a broadcast address, with my MAC address
I used Ethereal to dump packets on the Ethernet
I find my DHCP Discover packets successfully sending out, and the DHCP server in my LAN replies with a DHCP Offer message to my MAC address.
However, my client cannot receive it although the MAC address and port is correct, it contains no IP
Any ideas how to solve?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Indeed. Java doesn't offer sufficiently low-level access to the network stack to implement DHCP in 100% Java -- you would need to use native methods (or a library that itself uses native methods.)

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Writing DHCP client/server in JAVA
It's not a secret anymore!