i have a arduino uno r3 with a ethernet shield r3... it works fine with dhcp
i got an arduino mega with the another ethernet shield r3... so i know that the default hostname is WIZnet... i tried to compile changing the line #define Host_name WIZNET" to amega... and the arduino will not get DHCP ip.. but it worked if i put manual static ip in a local network via crossover cable.. but when i conect it to my dhcp at work it will not get an ip... so after a lot of trys.. i change the hostname to WIZnet again.. and voila it works...
so now that i have two arduinos with the same hostname but different ips due to different macs, i will have problems... so how do i change the hostname and make it work on dhcp...?
That's just the hostname that is transferred to the DHCP server as an ident. It's not used anywhere else than in the DHCP server. My DHCP server is configured to give the IPs for MAC addresses not the presented hostname. Is your's different? I've never seen a DHCP server that had problems with identical hostnames, as long as the MACs are unique.
What problems do you get? Why do you wanna change that name?
BTW: The name "WIZnet" is not used directly but prepended to the last 3 bytes of the MAC address. The resulting string is presented to the DHCP server.
// OPT - host name
buffer[16] = hostName;
buffer[17] = strlen(HOST_NAME) + 6; // length of hostname + last 3 bytes of mac address
strcpy((char*)&(buffer[18]), HOST_NAME);
printByte((char*)&(buffer[24]), _dhcpMacAddr[3]);
printByte((char*)&(buffer[26]), _dhcpMacAddr[4]);
printByte((char*)&(buffer[28]), _dhcpMacAddr[5]);
As you can see the HOST_NAME is copied in buffer positions 18-23 so if you would like to use your own, either it has to be 6 characters long or you have to edit the code above. Also, there might exists a little bug here, as it should be:
buffer[17] = strlen(HOST_NAME) + 3;
So you could try:
// OPT - host name
buffer[16] = hostName;
uint8_t len = strlen(HOST_NAME);
buffer[17] = len + 3; // length of hostname + last 3 bytes of mac address
strcpy((char*)&(buffer[18]), HOST_NAME);
printByte((char*)&(buffer[18+len]), _dhcpMacAddr[3]);
printByte((char*)&(buffer[19+len]), _dhcpMacAddr[4]);
printByte((char*)&(buffer[20+len]), _dhcpMacAddr[5]);
However, be careful with the HOST_NAME length because:
uint8_t buffer[32];
so max length would be 32-18-3 = 11 characters or 14 chars if you omit the last 3 bytes of mac address.
I don't think that the '+6' is a bug. It seems that the last three bytes must be expressed as the characters corresponding to their hex values. This comes out to 6 characters total, but represents 3 bytes.
For example with a mac address of 90 A2 DA 0E 60 A0, the default hostname would be wiznet0E60A0