summaryrefslogtreecommitdiff
path: root/support/dktools/itaether.c
blob: 5725b186d54da1da87d66d81a2cb5bdb5c7db77a (plain)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
Copyright (C) 2012-2020, Dirk Krause
SPDX-License-Identifier: BSD-3-Clause
*/

/*
	WARNING: This file was generated by the dkct program (see
	http://dktools.sourceforge.net/ for details).
	Changes you make here will be lost if dkct is run again!
	You should modify the original source and run dkct on it.
	Original source: itaether.ctr
*/

/**	@file itaether.c The itaether module.
*/


#line 11 "itaether.ctr"


#include "dk3all.h"
#include "itadmin.h"





#line 19 "itaether.ctr"



/**	Keywords used by the module.
*/
static char const * const itadmin_ethers_c8_kw[] = {
/* 0 */
"\n",

/* 1 */
"w",

/* 2 */
"ethers-by-ip",

/* 3 */
"ethers-by-mac",

/* 4 */
"ethers.ldif",

/* 5 */
"dn: cn=",

/* 6 */
",ou=ethers,",

/* 7 */
"objectClass: ieee802Device",

/* 8 */
"objectClass: device",

/* 9 */
"objectClass: top",

/* 10 */
"cn: ",

/* 11 */
"macAddress: ",

NULL


#line 75 "itaether.ctr"
};




int
itadmin_ethers_output(itadmin_job *job)
{
  itadmin_host		*host;
  FILE			*f1;
  FILE			*f2;
  int			 back	= 0;
  

#line 88 "itaether.ctr"
  f1 = dk3sf_c8_fopen_app(
    itadmin_ethers_c8_kw[2],
    itadmin_ethers_c8_kw[1],
    job->app
  );
  if(f1) {
    f2 = dk3sf_c8_fopen_app(
      itadmin_ethers_c8_kw[3],
      itadmin_ethers_c8_kw[1],
      job->app
    );
    if(f2) {
      back = 1;
      dk3sto_it_reset(job->i_hoi);
      while(NULL != (host = (itadmin_host *)dk3sto_it_next(job->i_hoi))) {
        if((host->ipv4) && (host->sn) && (host->maca)) {
	  itadmin_tool_write_ip(f1, host->ipv4);
	  fputc('\t', f1);
	  fputs(host->maca, f1);
	  fputc('\n', f1);
	  fputs(host->maca, f2);
	  fputc('\t', f2);
	  itadmin_tool_write_ip(f2, host->ipv4);
	  fputc('\n', f2);
	}
      }
#if DK3_CHAR_SIZE == 1
      if(!dk3sf_fclose_fn_app(f2, itadmin_ethers_c8_kw[3], job->app)) {
        back = 0;
      }
#else
      if(!dk3sf_fclose_fn_app(f2, NULL, job->app)) {
        back = 0;
      }
#endif
    } else {
    }
#if DK3_CHAR_SIZE == 1
    if(!dk3sf_fclose_fn_app(f1, itadmin_ethers_c8_kw[2], job->app)) {
      back = 0;
    }
#else
    if(!dk3sf_fclose_fn_app(f1, NULL, job->app)) {
      back = 0;
    }
#endif
  } else {
  }
  

#line 137 "itaether.ctr"
  return back;
}



int
itadmin_ethers_ldif_output(itadmin_job *job)
{
  char			 bu[ITADMIN_CONFIG_LINE_SIZE];
  itadmin_host		*host;
  FILE			*fipo;
  int			 ie;
  int			 back	= 0;
  

#line 151 "itaether.ctr"
  ie = dk3app_get_encoding(job->app);
  if(dk3str_to_c8u_app(bu,sizeof(bu),job->ldapb,ie,job->app)) {
    fipo = dk3sf_c8_fopen_app(
      itadmin_ethers_c8_kw[4],
      itadmin_ethers_c8_kw[1],
      job->app
    );
    if(fipo) {
      back = 1;
      dk3sto_it_reset(job->i_hoi);
      while(NULL != (host = (itadmin_host *)dk3sto_it_next(job->i_hoi))) {
        if((host->ipv4) && (host->sn) && (host->maca)) {
          fputs(itadmin_ethers_c8_kw[5], fipo);
	  itadmin_tool_write_ip(fipo, host->ipv4);
	  fputs(itadmin_ethers_c8_kw[6], fipo);
	  fputs(bu, fipo);
	  fputc('\n', fipo);
	  fputs(itadmin_ethers_c8_kw[7], fipo);
	  fputc('\n', fipo);
	  fputs(itadmin_ethers_c8_kw[8], fipo);
	  fputc('\n', fipo);
	  fputs(itadmin_ethers_c8_kw[9], fipo);
	  fputc('\n', fipo);
	  fputs(itadmin_ethers_c8_kw[10], fipo);
	  itadmin_tool_write_ip(fipo, host->ipv4);
	  fputc('\n', fipo);
	  fputs(itadmin_ethers_c8_kw[11], fipo);
	  fputs(host->maca, fipo);
          fputc('\n', fipo); fputc('\n', fipo);
        }
      }
#if DK3_CHAR_SIZE == 1
      if(!dk3sf_fclose_fn_app(fipo, itadmin_ethers_c8_kw[4], job->app)) {
        back = 0;
      }
#else
      if(!dk3sf_fclose_fn_app(fipo, NULL, job->app)) {
        back = 0;
      }
#endif
    } else {
    }
  } else {
  }
  

#line 196 "itaether.ctr"
  return back;
}