In article <[EMAIL PROTECTED]>, Alfonso Ranieri <[EMAIL PROTECTED]>
wrote:

> David wrote:
> 
> 
> > It doesn't crash here, just returns -1. To set a route, use either ioctl()
> > with SIOCADDRT or use a routing message with rt_msghdr (net/route.h).
> > 
> > If you need some more sources on how to do it, just ask.
> > 
> 
> I know, It was just testing an "ip2if.rexx" macro that uses rt_msghdr that I
> had the first crash. Anyway, the socket to open is (AF_ROUTE,SOCK_RAW,0) and
> it crashes here with a "Check instruction error" .

Apart from the socket() problem, which may or may not be a bug in
Genesis (I don't know), I would be very careful when trying to access
the routing socket layer across different protocol stacks. Unlike the
binary-compatible IP/UDP/TCP APIs, the routing API was meant to be
compatible across protocol stacks at the *source* level only, not at
the binary level, i.e. the idea is that programs using it are
recompiled for each new platform. That's because complex structures
need to be exchanged in routing messages, and providing full binary
compatibility across stack generations would be very difficult to
design. That's why there is a version code (RTM_VERSION), to at least
be able to detect mismatches at run time.

Genesis (a 4.3BSD-Reno-derived stack) defines RTM_VERSION to be 2.
Miami (a FreeBSD-2.x-derived stack) defines RTM_VERSION to be 4.
Consequently the layout of routing structures is different. Miami
needs some additional fields and flags because of route cloning,
T/TCP, PMTU etc., and pads fields to ensure alignment to 4-byte
boundaries, for PPC compatibility. Genesis only guarantees 2-byte
alignment, because pid_t (a "short" in Unix) is defined as
"struct Task *" in Genesis, throwing off the alignment by 2 bytes.
The different alignment makes accesses binary-incompatible between
Miami and Genesis, and you need to watch out for that in your code.

Another difference is that in Genesis rtm_pid has to be compared
against FindTask(0) for returned routing messages. In Miami it has
to be compared against miami.library/MiamiGetPid().

If you really want to provide any kind of routing socket support in a
shared library for both stacks then you need to do a runtime check for
miami.library and genesis.library, and link your library with two
versions of your code: one compiled against the AmiTCP SDK for Genesis
and one compiled against MiamiSDK for Miami/MiamiDx.

If you want to return an interface name from your function then you
also have to worry about how to convert an interface index, as
returned by the routing API, into an interface name. Newer versions
of Miami provide an RFC-2133-compliant miami.library/if_indextoname().
I am not sure how to do this in Genesis. If there is no such function
then the obvious solution as documented by Stevens is via
sysctl()/CTL_NET/AF_ROUTE, but that's for BSD >=4.4 only. In Genesis
you could try using IoctlSocket() with SIOCGIFCONF to get a list of
interfaces, and then iterate through that list.

-- 
Holger Kruse   [EMAIL PROTECTED]
               http://www.nordicglobal.com
               NO COMMERCIAL SOLICITATION !


____________________________________________________________
Genesis Mailing List - Info & Archive: http://www.vapor.com/
For Listserver Help: <[EMAIL PROTECTED]>, "HELP"
To Unsubscribe: <[EMAIL PROTECTED]>, "UNSUBSCRIBE"

Reply via email to