[sclug] C programming question and date on Linux

Rick Payne rickp at rossfell.co.uk
Sat Oct 25 09:05:36 UTC 2003


--On Thursday, April 10, 2003 4:42 pm +0100 pieter claassen 
<pieter at openauth.co.uk> wrote:

> Hello All,
>
> Here are two simple questions.
> 1. Why does C on linux have such cool undocumented data types such as
> u_int16_y and where are they documented? My Kernighan and Ritchie says
> nothing about them. How do I know when I write a program which ones I am
> supposed to use? Also, if I look through the /net/ethernet.h I get the
> following declaration

The u_intxx_t types seem to be a semi-standard - and may even be an 
official one. It helps to be specific when you're typing things that you 
want to be specific bit-sizes (ie. where 'int' just won't do).

> struct ether_header
> {
>   u_int8_t  ether_dhost[ETH_ALEN];      /* destination eth addr */
>   u_int8_t  ether_shost[ETH_ALEN];      /* source ether addr    */
>   u_int16_t ether_type;                 /* packet type ID field */
> } __attribute__ ((__packed__));
>
> What is the __attribute__((__packed__)); about and where can I get more
> info on that? How do I find out where ETH_ALEN comes from?

__attribute__((__packed__)) is a gross hack provided by gcc to allow you to 
break the normal rules 'C' would use when putting things into a structure. 
Its most commonly used when trying to make a structure that matches a 
packet or file format, as seen in your example. I use it all the time, but 
its still a gross hack.

I'd just use brute force to find where ETH_ALEN was defined ('find . -type 
f | xargs grep ETH_ALEN', seasoned to taste).

> 2. My PC clock is always way out and it seems to stay out. Firstly, how
> do I set daylight savings in the command line and is there a simpler way
> to set the date than with date -s foo? Is there is way to stop this
> problem (there must be time servers online with appropriate clients that
> does this magic securely)?

Use ntp to keep your clock in sync with the world. Do not worry about 
daylight saving time - unix solved that problem years ago. Set the correct 
timezone, and your time will shift to daylight saving time appropriately.

Rick




More information about the Sclug mailing list