weird structure conversion in bsd TCP/IP src..

weird structure conversion in bsd TCP/IP src..

Post by Pau » Fri, 01 Feb 2002 13:47:13



Hi All,

Looking into 'ether_output()' in Net/3 TCP/IP src,
there is a weird line:

int ether_output(struct ifnet ifp,..){
...
struct arpcom *ac=(struct arpcom *)ifp; //=>This is werid!

.....

Quote:}

Actually struct arpcom{} consists like:
struct arpcom{
 struct ifnet ac_if;
 u_char ac_enaddr[6];
 ...

Quote:}

Since arpcom structure is larger than 'ifnet'.So I think 'struct
arpcom *ac=(struct arpcom *)ifp' is very dangerous.

Can anybody tell me how this weird assignment works well in Net.3 src?

thanks

 
 
 

weird structure conversion in bsd TCP/IP src..

Post by Ben Harr » Fri, 01 Feb 2002 21:50:34




>Hi All,

>Looking into 'ether_output()' in Net/3 TCP/IP src,
>there is a weird line:

>int ether_output(struct ifnet ifp,..){
>...
>struct arpcom *ac=(struct arpcom *)ifp; //=>This is werid!

>.....
>}

>Actually struct arpcom{} consists like:
>struct arpcom{
> struct ifnet ac_if;
> u_char ac_enaddr[6];
> ...
>}

>Since arpcom structure is larger than 'ifnet'.So I think 'struct
>arpcom *ac=(struct arpcom *)ifp' is very dangerous.

>Can anybody tell me how this weird assignment works well in Net.3 src?

All ifnet structures that will be passed to ether_output() are actually the
first elements of arpcom structures.  This means that any pointer to one of
those ifnet structures can safely be cast to a struct arpcom *, since
there's guaranteed to be a complete arpcom structure starting at that
address.  This is a common method of implementing subclassing in C
(especially in BSD kernels).

--
Ben Harris
Unix Support, University of Cambridge Computing Service.
  If I wanted to speak for the University, I'd be in ucam.comp-serv.announce.

 
 
 

1. Src Code for Comer: internetworking with TCP/IP

Dear,
From which site can I get the source code in the book "Internet working
with TCP/IP vol 3" by Douglas E. Comer

Thanks in advance
subrahmanyam

--

J.N. Subrahmanyam
Software Engineer
IBM India Ltd.
PARVAAZ Building
Shanker Shet Road
PUNE - 411 001



  jsubrahm.vcf
< 1K Download

2. Two NICs

3. Help with TCP/IP files/data structures.

4. lpr problem, also, clearing up two other problems

5. Linux TCP/IP structures

6. Printing From Netscape?

7. !!DDE->TCP/IP, REAL TIME DATA PUMP, Trans.DDE App.DATA via TCP/IP

8. system cpu utilization

9. SLS X wants tcp/ip, tcp/ip won't compile, what now?