You're asking why something that doesn't exist can't be found? It can't be found because it doesn't exist.
What would you like the sysctl to return if there's no serialno? On Tue, Sep 28, 2010 at 10:36 AM, Destan YILANCI (Parta) <dyila...@parta.com.tr> wrote: > Hello Everyone, > > I want to get serial number of hardware with handling sysctl. I've got a > little code below: > > #include <stdio.h> > #include <string.h> > #include <errno.h> > #include <sys/param.h> > #include <sys/sysctl.h> > > int main(int argc, char **argv) > { > char cpubuf[1024]; > size_t len; > int mib[5]; > > mib[0] = CTL_HW; > mib[1] = HW_SERIALNO; > len = sizeof(cpubuf); > if (sysctl(mib, 2, &cpubuf, &len, NULL, 0) == -1) { > printf("HW_SERIALNO %s\n", strerror(errno)); > return(1); > } > > printf("cpu: %s\n", cpubuf); > > return 0; > } > > But i realized that some of my machines cant get "sysctl hw.serialno" so > it's normal that C code fails with this error message : HW_SERIALNO > Operation not supported > > So if we return to the source, why sysctl cant handle some of hardware > serial numbers? > > Thank you. > > P.S. > I want to provide a working sysctl.hw ouput here: > hw.machine=i386 > hw.model=Intel(R) Xeon(R) CPU E5440 @ 2.83GHz ("GenuineIntel" 686-class) > hw.ncpu=8 > hw.byteorder=1234 > hw.pagesize=4096 > hw.disknames=sd0,sd1,sd2,sd3,sd4,cd0 > hw.diskcount=6 > hw.sensors.cpu0.temp0=44.00 degC > hw.sensors.mpi0.drive0=online (sd0), OK > hw.cpuspeed=2827 > hw.setperf=99 > hw.vendor=Sun Microsystems > hw.product=Sun Fire X4150 > hw.serialno=2029QTF0814MR0GYD > hw.uuid=6236f661-097a-0010-915a-001e682f5f0c > hw.physmem=3757338624 > hw.usermem=3756867584 > hw.ncpufound=8 > > And here is a not working hw.serialno : > # sysctl hw > hw.machine=i386 > hw.model=AMD Athlon(tm) 64 X2 Dual Core Processor 3800+ ("AuthenticAMD" > 686-class, 512KB L2 cache) > hw.ncpu=2 > hw.byteorder=1234 > hw.pagesize=4096 > hw.disknames=cd0,wd0 > hw.diskcount=2 > hw.sensors.acpitz0.temp0=40.00 degC (zone temperature) > hw.sensors.aibs0.temp0=34.00 degC (CPU Temperature), OK > hw.sensors.aibs0.temp1=43.00 degC (MB Temperature), OK > hw.sensors.aibs0.fan0=1288 RPM (CPU FAN Speed), WARNING > hw.sensors.aibs0.fan1=1138 RPM (CHASSIS FAN Speed), WARNING > hw.sensors.aibs0.volt0=1.27 VDC (Vcore Voltage), WARNING > hw.sensors.aibs0.volt1=3.18 VDC ( +3.3 Voltage), OK > hw.sensors.aibs0.volt2=4.98 VDC ( +5.0 Voltage), OK > hw.sensors.aibs0.volt3=11.98 VDC (+12.0 Voltage), OK > hw.sensors.kate0.temp0=36.00 degC > hw.sensors.kate0.temp2=35.00 degC > hw.sensors.it0.temp0=34.00 degC > hw.sensors.it0.temp1=43.00 degC > hw.sensors.it0.temp2=25.00 degC > hw.sensors.it0.fan0=1288 RPM > hw.sensors.it0.fan1=1138 RPM > hw.sensors.it0.fan2=0 RPM > hw.sensors.it0.volt0=1.12 VDC (VCORE_A) > hw.sensors.it0.volt1=3.18 VDC (VCORE_B) > hw.sensors.it0.volt2=0.00 VDC (+3.3V) > hw.sensors.it0.volt3=4.78 VDC (+5V) > hw.sensors.it0.volt4=11.58 VDC (+12V) > hw.sensors.it0.volt5=-17.00 VDC (-12V) > hw.sensors.it0.volt6=-8.60 VDC (-5V) > hw.sensors.it0.volt7=4.57 VDC (+5VSB) > hw.sensors.it0.volt8=2.88 VDC (VBAT) > hw.cpuspeed=2010 > hw.setperf=100 > hw.vendor=ASUSTek Computer INC. > hw.product=M2NPV-VM > hw.uuid=11111111-1111-1111-1111-111111111111 > hw.physmem=1038643200 > hw.usermem=1038565376 > hw.ncpufound=2 > > Any other not working output is also here: > # sysctl hw > hw.machine=i386 > hw.model=VIA Eden Processor 1000MHz ("CentaurHauls" 686-class) > hw.ncpu=1 > hw.byteorder=1234 > hw.pagesize=4096 > hw.disknames=wd0 > hw.diskcount=1 > hw.sensors.fins0.temp0=29.00 degC > hw.sensors.fins0.temp1=26.00 degC > hw.sensors.fins0.temp2=109.00 degC > hw.sensors.fins0.fan0=6849 RPM > hw.sensors.fins0.volt0=3.39 VDC (+3.3V) > hw.sensors.fins0.volt1=0.85 VDC (Vtt) > hw.sensors.fins0.volt2=1.44 VDC (Vram) > hw.sensors.fins0.volt3=1.66 VDC (Vchips) > hw.sensors.fins0.volt4=5.13 VDC (+5V) > hw.sensors.fins0.volt5=11.97 VDC (+12V) > hw.sensors.fins0.volt6=1.11 VDC (+1.5V) > hw.sensors.fins0.volt7=1.08 VDC (Vcore) > hw.sensors.fins0.volt8=5.05 VDC (Vsb) > hw.cpuspeed=1001 > hw.setperf=58 > hw.product=CN700-8237 > hw.uuid=Not Set > hw.physmem=1005023232 > hw.usermem=1005010944 > hw.ncpufound=1 > > -- > Destan YILANCI > www.parta.com.tr