Host Name length in MAC

S

sjain

Guest
Hi,

What is the maximum host name length defined by the OS. i mean, i had defined a 100 bytes of array which stores the hostname of my OS. I am porting the code for various flavours of Unix( Linux, HP UX, Solaris, AIX) and now MAC. But on MAC, i faced this issue where my hostname length exceeded this value of 100 and i got this segmentation fault. merely increasing it to 256 runs me into more issues. so by hit and trial method i have ended up taking 156 as the value of the array which works fine with me. but i am not satisfied with this approach. There must be a maximum value defined by the OS itself that it assigns itself for the hostname, ( some form of macro), which will give me a better approach to solve the issue. If anybody has any idea regarding this, please let me know ASAP.

Thanks a lot in advance

Regards
Sjain
 
Joined
Jun 25, 2005
Messages
3,231
Reaction score
112
Points
63
Location
On the road
Your Mac's Specs
2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
Many of these type of values can be found in the header files. So something like this may help you.

grep -i host /usr/include/*/*.h | grep -Ei '(size|length)'

It looks like there could be multiple answers. Which ever one you choose, you should try to use the variable in your code on all the platforums your coding for. You should only define your own lenght as a last option. This may be a case where you use DEFINES that are platform dependent, unless they all share the same variable name and include file.

Anyway, that is the extent of my C knowledge for this case.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top