Operating System - HP-UX
1753878 Members
7339 Online
108809 Solutions
New Discussion юеВ

Re: struct utsname throwing error : Value too large to be stored in data type

 
shivarajbm
Occasional Contributor

struct utsname throwing error : Value too large to be stored in data type

Hi,
I am trying to fetch sysname and nodename using struct utsname. I have two HP-UX servers on with 10 characters and other with 13 characters host name. For the first one I am getting truncated 8 characters as output but for the second one i am getting "Value too large to be stored in data type" error. Why this is so ?
What should I do to avoid getting this error ?

Here is the sample code which I am using :

code:
#include
#include

int main()
{
struct utsname uts;

if(uname(&uts) != -1)
{
printf("\n sysname :%s",uts.sysname);
printf("\n nodename :%s",uts.nodename);
}
else
{
printf( "Error fetching uname: %s\n", strerror( errno ) );
perror( "Error fetching uname :" );
}
return 0;
}
6 REPLIES 6
Dennis Handly
Acclaimed Contributor

Re: struct utsname throwing error : Value too large to be stored in data type

How are you compiling your source? If you don't do anything, you are limited to 8 bytes.
You can configure the kernel so that it gives that above error if longer than 8, rather than silently truncating it.
shivarajbm
Occasional Contributor

Re: struct utsname throwing error : Value too large to be stored in data type

Hmm...Did not exactly get the point. The compiler which I am using is aCC.
And regarding kernel configurations to throw this error rather than truncating the same, if you could let me know what changes to kernel will make me get first 8 bytes will be great.

Dennis Handly
Acclaimed Contributor

Re: struct utsname throwing error : Value too large to be stored in data type

>The compiler which I am using is aCC.

With what options?

Have you looked at uname(2), nodehostnamesize(5) and uname_eoverflow(5)? They point to the whitepaper "Node and Host Name Sizes on HP-UX: Using the Expanded Capabilities":
http://bizsupport2.austin.hp.com/bc/docs/support/SupportManual/c01925495/c01925495.pdf

To turn off error reporting:
kctune uname_eoverflow=0

There is a warning that in the future it may not truncate but just return an empty string and suggests calling gethostname(2).
shivarajbm
Occasional Contributor

Re: struct utsname throwing error : Value too large to be stored in data type

Hi, thanks for giving a link for the whitepaper. http://bizsupport2.austin.hp.com/bc/docs/support/SupportManual/c01925495/c01925495.pdf

 

What I did is, on the machine where I am getting truncated name, tried setting "

kctune uname_eoverflow=1" so that I can reproduce the error. But when I ran my sample CPP program, I got truncated node name!! Basically either setting this value to 0 or 1 is always returning my the truncated node name. I am not able to reproduce the error in my first box.

 

Could not try this on second box as this is a production setup. Once I am sure that setting this properly really works as expected, will try it on the box where I am getting this error.

 

Any idea why this is so?



Dennis Handly
Acclaimed Contributor

Re: struct utsname throwing error : Value too large to be stored in data type

>I got truncated node name!! Basically either setting this value to 0 or 1 is always returning me the truncated node name. I am not able to reproduce the error in my first box.

I would expect that error and possibly a truncated name.  I wouldn't think the 10 vs. 13 length would suppress the error.

>will try it on the box where I am getting this error.

I thought you didn't want the error?  And were OK with the name being truncated.

Rajesh K Chaurasia
Valued Contributor

Re: struct utsname throwing error : Value too large to be stored in data type

If using expanded nodename / hostname feature on HP-UX 11i v3, you need to add the option -D_HPUX_API_LEVEL=20040821 to compile line in respective make files. This option will enable selection of expanded utsname structure from /usr/include/sys/utsname.h

 

Regards

-Rajesh