This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: issue with raw bsd sockets


On Fri, Aug 7, 2009 at 9:50 PM, Jay Foster<jay@systech.com> wrote:
> DHCP uses INADDR_BROADCAST (255.255.255.255) as the broadcast address. You
> probably need to set the interface broadcast address to match. ?You may also
> need to add a route to allow broadcasts. ?Look at the DHCP/BOOTP eCos code.
> ?It does some of this too.

I've setup my 'eth0' interface with a static address (config
time...not the manual setup).

IP: 10.1.1.1
netmask: 255.255.255.0
Broadcast: 255.255.255.255
gateway IP: 0
server IP: 0

Now I followed the dhcp test code to see how they are able to send
bcast UDP packets.
It set 'eth0's IP as 0.0.0.0 and the broadcast addr as
255.255.255.255. Then it adds
a route entry for the broadcast IP, where gw IP is 255.255.255.255 and
dst addr is
0.0.0.0 and device name is 'eth0'. This basically means that the
default route has gw
as 255.255.255.255 and dev eth0.

I did something similar but sans the interface setup part (cos that's
already done at setup
time). I'm pasting a part of that code. But the problem is that when I
try to add this route it
says that the 'Network is unreachable'!! :(

Should I purge the existing routing table before adding my route
entry? The dhcp code
does that via a call to cyg_route_reinit().

(i've remove error check here to keep it short...but the actual code
is checking for all
return values etc etc )

Should I try the more cumbersome 'manual' setup of eth0?

<snip>
...
struct sockaddr_in addrp;
struct ecos_rtentry route;

s = socket(AF_INET, SOCK_DGRAM, 0);
setsockopt(s, SOL_SOCKET, SO_BROADCAST, &one, sizeof(one))
memset(&addrp, 0, sizeof(addrp));

    // Set up routing
    addrp.sin_family = AF_INET;
    addrp.sin_port = 0;
    addrp.sin_len = sizeof(addrp);  // Size of address

    /* the broadcast address is 255.255.255.255 */
    memset(&addrp.sin_addr, 255, sizeof(addrp.sin_addr));
    memset(&route, 0, sizeof(route));
    memcpy(&route.rt_gateway, &addrp, sizeof(addrp));

    addrp.sin_addr.s_addr = INADDR_ANY;
    memcpy(&route.rt_dst, &addrp, sizeof(addrp));
    memcpy(&route.rt_genmask, &addrp, sizeof(addrp));

    route.rt_dev = ifrp.ifr_name;
    route.rt_flags = RTF_UP|RTF_GATEWAY;
    route.rt_metric = 0;

    if (ioctl(s, SIOCADDRT, &route)) { /* add route */
        if (errno != EEXIST) {
            perror("SIOCADDRT 3");
            goto out;
        }
    }
...
</snip>



>
> Jay
>
> Mandeep Sandhu wrote:
>>
>> On Fri, Aug 7, 2009 at 6:21 PM, Sergei
>> Gavrikov<sergei.gavrikov@gmail.com> wrote:
>>>
>>> Mandeep Sandhu wrote:
>>>>
>>>> I'm using the FreeBSD stack on my Linux Synthetic target to implement
>>>> a tiny DHCP server. I can receive DHCP REQUEST packets coming over the
>>>> tap interface, but am unable to send back the broadcast resp packet
>>>> (DHCP Offer).
>>>
>>> [snip]
>>>
>>>> Any hint's appreciated.
>>>
>>> Hi Mandeep,
>>>
>>> I call that recently Jay Foster share on the list a solution
>>> http://sourceware.org/ml/ecos-discuss/2009-06/msg00075.html
>>> Follow this thread. HIH.
>>
>> Thanks Sergei. This is _exactly_ my problem too.
>>
>> Though this patch didn't help much. Now my IP broadcast addr is not
>> converted to the subnet bcast addr of the interface...but my ip_output
>> function fails when trying to get an interface for 255.255.255.255
>>
>> Here's where it fails:
>>
>> packages/net/bsd_tcpip/v3_0/src/sys/netinet/ip_output.c
>>
>> <snip>
>> ...
>> ? ?if (flags & IP_ROUTETOIF) {
>> ? ? ? ?if ((ia = ifatoia(ifa_ifwithdstaddr(sintosa(dst)))) == 0 &&
>> ? ? ? ? ? ?(ia = ifatoia(ifa_ifwithnet(sintosa(dst)))) == 0) { <<----
>> PROBLEM!
>> ? ? ? ? ? ?ipstat.ips_noroute++;
>> ? ? ? ? ? ?error = ENETUNREACH; <<-- shows up as 'Network is unreachable'
>> ? ? ? ? ? ?goto bad;
>> ? ? ? ?}
>> ? ? ? ?ifp = ia->ia_ifp;
>> ? ? ? ?ip->ip_ttl = 1;
>> ? ? ? ?isbroadcast = in_broadcast(dst->sin_addr, ifp);
>> ? ?}
>> ...
>> </snip>
>>
>> Any other clue? Or should I switch stack to LWIP? Any idea if this works
>> in
>> LWIP?
>>
>> Looking at the same function in lwip stack...I see it picks up the
>> default interface
>> if the route lookup does not find a suitable match.
>>
>> Thanks,
>> -mandeep
>>
>>> Sergei
>>>
>>
>

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]