File: util.c

package info (click to toggle)
rpld 1.8beta1-6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 832 kB
  • ctags: 621
  • sloc: ansic: 2,230; asm: 434; yacc: 225; makefile: 169; sh: 40
file content (110 lines) | stat: -rw-r--r-- 2,048 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*************************************************
*     rpld - an IBM style RIPL server            *
*************************************************/

/* Copyright (c) 1999,2000,2001 James McKenzie.
 *                      All rights reserved
 * Copyright (c) 1998,2000,2001 Christopher Lightfoot.
 *                      All rights reserved
 *
 * NetBSD and BPF support by Takashi YAMAMOTO
 * Copyright (C) 2001 YAMAMOTO Takashi <yamt@netbsd.org>.
 *
 *
 * By using this file, you agree to the terms and conditions set
 * forth in the LICENCE file which can be found at the top level of
 * the rpld distribution.
 *
 * IBM is a trademark of IBM corp.
 *
 */


static char rcsid[] = "$Id: util.c,v 1.9 2001/11/01 15:24:26 root Exp $";

/*
 * $Log: util.c,v $
 * Revision 1.9  2001/11/01 15:24:26  root
 * #
 *
 * Revision 1.8  2001/11/01 15:23:59  root
 * #
 *
 * Revision 1.7  2000/07/16 14:05:28  root
 * #
 *
 * Revision 1.6  2000/07/16 13:18:10  root
 * #
 *
 * Revision 1.1  2000/07/16 13:16:33  root
 * #
 *
 * Revision 1.5  1999/09/13 11:17:35  root
 * \#
 *
 * Revision 1.4  1999/09/13 11:05:27  root
 * \#
 *
 * Revision 1.3  1999/09/13 11:04:13  root
 * \#
 *
 */

#include "project.h"


unsigned char ethtoaret[1024];

unsigned char *
ethtoa (void *in)
{
  unsigned char *p = (unsigned char *) in;
  int i = ETH_ALEN;
  int len = 0;

  len += sprintf (ethtoaret + len, "%02x", *(p++));

  while (--i)
    len += sprintf (ethtoaret + len, ":%02x", *(p++));

  return (ethtoaret);
}

#ifdef __NetBSD__
void
daemonize (void)
{
  if (daemon (1, 0) == -1)
    {
      openlog ("rpld", LOG_PID, LOG_DAEMON);
      syslog (LOG_ERR, "fork failed: %m");
      exit (1);
    }
}
#else
void
daemonize (void)
{
  int fd;

  switch (fork ())
    {
    case 0:
      break;
    case -1:
      openlog ("rpld", LOG_PID, LOG_DAEMON);
      syslog (LOG_ERR, "fork failed: %m");
      exit (1);
    default:
      exit (0);
    }

  setpgrp ();

  fd = open ("/dev/null", O_RDWR);
  dup2 (fd, 0);
  dup2 (fd, 1);
  dup2 (fd, 2);
  close (fd);
}
#endif