tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: computer-friendly way of accessing ifconfig



On 22/05/2016 15:22, coypu%SDF.ORG@localhost wrote:
> hi,
> 
> I'd like to write code that works with the input or output typically
> done with ifconfig.
> as an example, I would like to know, say, which interfaces are wireless
> and which are wired, as they tend to be controlled differently, and
> whether they are up.
> 
> my options currently seem to be:
> 1. parse the output
> 2. make my own modified ifconfig
> 
> is there another one?

Are you after something portable to other os or netbsd specific?
ifconfig output varies a lot from OS to OS and even from OS revision to
OS revision.

Anyway, here are link to how dhcpcd does it in C.

1) wireless or not - test error getting SSID (BSD specific)
http://nxr.netbsd.org/xref/src/external/bsd/dhcpcd/dist/if-bsd.c#if_getssid1

2) carrier up or not (Linux and BSD)
http://nxr.netbsd.org/xref/src/external/bsd/dhcpcd/dist/if.c#130

Roy


Home | Main Index | Thread Index | Old Index