OS/2 codes: How to pass packets to a specific interface

While developing kipcfg, DHCP client, what I want to know eagerly is to pass packets to a specific interface because it's the requirement of the DHCP client.

If it is not implemented, DHCP client cannot get an IP address from the requested interface. The address that client gets from a server, may not be from the server connected to the requested interface.

Because of this, I've tried to assign an temporary private IP address such as 172.x.x.x. However, IBM's dhcpcd.exe does not require this workaround.

With AI progress, I've tried to use Claude to know the way that dhcpcd.exe does. First try was on Aug. 2026. At that time, Claude said that it cannot parse LX executables. However, on Nov. 2026, Claude made tools to parse LX exectuable by itself. I'm not sure what changes during this period, maybe the difference of free model and charged model ?

Anyway, Claude found the way dhcpcd.exe does. It's using SO_L_BROADCAST socket option.

SO_L_BROADCAST is used for two things:

1. When sending: SO_BROADCAST with SO_L_BROADCAST send packets via all the interfaces which is up.

2. When receiving: recvfrom() wrote IPv4 address to sin_zero of sockaddr_in if SO_L_BROADCAST socket option is enabled for a socket. dhcpcd.exe identified the requested interface with this info.

dhcpcd.exe does like this:

1. Initialize an address of the requested interface to 0.0.0.0.

2. Broadcast packets with SO_BROADCAST and SO_L_BROADCAST.

3. Receive packets with recvfrom() with SO_L_BROADCAST and check if the value of sin_zero of sockaddr_in is 0.0.0.0.

In this way, dhcpcd.exe can get a correct IP address for the requested interface. However, this way has a critical problem. It's not possible to distinguish from the requested interface if there are two or more interfaces having 0.0.0.0. Because of this, dhcpcd.exe support only 1 interface.

In addition, there is another notice. recvfrom() always write the previous value to sin_zero unless SO_L_BROADCAST is not enabled, and this is system-wide value. That is, if some programs used recvfrom() with SO_L_BROADCAST, the value of sin_zero is used later even if SO_L_BROADCAST is not enabled until updating sin_zero with another recvfrom() with SO_L_BROADCAST.

Here is the example:

댓글

이 블로그의 인기 게시물

토렌트: < 왕좌의 게임 > 시즌 1 ~ 시즌 8 완결편 마그넷

토렌트: < 스타워즈 > Ep.1 ~ Ep.6 마그넷

한랭전선과 온난전선에 대한 역학적 이해