int
main(int argc, char **argv)
{
- char *pidfile;
+ char *pidfile, *p;
struct interface *ifp;
uint16_t family = 0;
int opt, oi = 0, sig = 0, i;
pid_t pid;
struct timespec ts;
struct utsname utn;
- const char *platform;
struct control_ctx control_ctx;
pidfile = NULL;
}
}
- platform = hardware_platform();
- if (uname(&utn) == 0)
- snprintf(vendor, VENDORCLASSID_MAX_LEN,
- "%s-%s:%s-%s:%s%s%s", PACKAGE, VERSION,
- utn.sysname, utn.release, utn.machine,
- platform ? ":" : "", platform ? platform : "");
- else
+ if (uname(&utn) == 0) {
+ p = vendor;
+ p += snprintf(vendor, VENDORCLASSID_MAX_LEN,
+ "%s-%s:%s-%s:%s", PACKAGE, VERSION,
+ utn.sysname, utn.release, utn.machine);
+ hardware_platform(p, VENDORCLASSID_MAX_LEN - (p - vendor));
+ } else
snprintf(vendor, VENDORCLASSID_MAX_LEN,
"%s-%s", PACKAGE, VERSION);
}
*p = '\0';
- while ((p = get_line(fp))) {
- i = sscanf(p, "%32[a-f0-9] %x %x %x %x"
- " %"TOSTRING(IF_NAMESIZE)"s\n",
- address, &ifindex, &prefix, &scope, &flags, name);
- if (i != 6 || strlen(address) != 32) {
+ while (fscanf(fp, "%32[a-f0-9] %x %x %x %x %"TOSTRING(IF_NAMESIZE)"s\n",
+ address, &ifindex, &prefix, &scope, &flags, name) == 6)
+ {
+ if (strlen(address) != 32) {
fclose(fp);
errno = ENOTSUP;
return -1;
# define SYS_NMLN 256
#endif
-static char march[SYS_NMLN];
-
-char *
-hardware_platform(void)
+int
+hardware_platform(char *str, size_t len)
{
int mib[2] = { CTL_HW, HW_MACHINE_ARCH };
+ char march[SYS_NMLN];
size_t len = sizeof(march);
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]),
- march, &len, NULL, 0) != 0)
- return NULL;
- return march;
+ march, &len, NULL, 0) != 0)
+ return -1;
+ return snprintf(str, len, ":%s", march);
}
#ifdef INET6
static ssize_t nrestore;
#endif
-char *
-hardware_platform(void)
+int
+hardware_platform(char *str, size_t len)
{
FILE *fp;
- char *buf, *p;
+ char buf[255];
if (mproc == NULL) {
errno = EINVAL;
- return NULL;
+ return -1;
}
fp = fopen("/proc/cpuinfo", "r");
if (fp == NULL)
- return NULL;
+ return -1;
- p = NULL;
- while ((buf = get_line(fp))) {
+ while (fscanf(fp, "%s : ", buf) != EOF) {
if (strncmp(buf, mproc, strlen(mproc)) == 0) {
- p = strchr(buf, ':');
- if (p != NULL && ++p != NULL) {
- while (*p == ' ')
- p++;
- break;
- }
+ fscanf(fp, "%s", buf);
+ fclose(fp);
+ return snprintf(str, len, ":%s", buf);
}
}
fclose(fp);
-
- if (p == NULL)
- errno = ESRCH;
- return p;
+ errno = ESRCH;
+ return -1;
}
#ifdef INET6
#ifndef PLATFORM_H
#define PLATFORM_H
-char *hardware_platform(void);
+int hardware_platform(char *, size_t);
#ifdef INET6
int check_ipv6(const char *, int);
int ipv6_dadtransmits(const char *);