1 /*
2 * dhcpcd - DHCP client daemon
3 * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
4 * All rights reserved
5
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28 #include <errno.h>
29 #include <stdio.h>
30 #include <string.h>
31
32 #include "common.h"
33 #include "platform.h"
34
35 static const char *mproc =
36 #if defined(__alpha__)
37 "system type"
38 #elif defined(__arm__)
39 "Hardware"
40 #elif defined(__avr32__)
41 "cpu family"
42 #elif defined(__bfin__)
43 "BOARD Name"
44 #elif defined(__cris__)
45 "cpu model"
46 #elif defined(__frv__)
47 "System"
48 #elif defined(__i386__) || defined(__x86_64__)
49 "vendor_id"
50 #elif defined(__ia64__)
51 "vendor"
52 #elif defined(__hppa__)
53 "model"
54 #elif defined(__m68k__)
55 "MMU"
56 #elif defined(__mips__)
57 "system type"
58 #elif defined(__powerpc__) || defined(__powerpc64__)
59 "machine"
60 #elif defined(__s390__) || defined(__s390x__)
61 "Manufacturer"
62 #elif defined(__sh__)
63 "machine"
64 #elif defined(sparc) || defined(__sparc__)
65 "cpu"
66 #elif defined(__vax__)
67 "cpu"
68 #else
69 NULL
70 #endif
71 ;
72
73 char *
hardware_platform(void)74 hardware_platform(void)
75 {
76 FILE *fp;
77 char *buf, *p;
78
79 if (mproc == NULL) {
80 errno = EINVAL;
81 return NULL;
82 }
83
84 fp = fopen("/proc/cpuinfo", "r");
85 if (fp == NULL)
86 return NULL;
87
88 p = NULL;
89 while ((buf = get_line(fp))) {
90 if (strncmp(buf, mproc, strlen(mproc)) == 0) {
91 p = strchr(buf, ':');
92 if (p != NULL && ++p != NULL) {
93 while (*p == ' ')
94 p++;
95 break;
96 }
97 }
98 }
99 fclose(fp);
100
101 if (p == NULL)
102 errno = ESRCH;
103 return p;
104 }
105