Deleted Added
full compact
net.c (70098) net.c (78146)
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 26 unchanged lines hidden (view full) ---

35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * From: @(#)common.c 8.5 (Berkeley) 4/28/95
39 */
40
41#ifndef lint
42static const char rcsid[] =
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 26 unchanged lines hidden (view full) ---

35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * From: @(#)common.c 8.5 (Berkeley) 4/28/95
39 */
40
41#ifndef lint
42static const char rcsid[] =
43 "$FreeBSD: head/usr.sbin/lpr/common_source/net.c 70098 2000-12-16 18:06:09Z ume $";
43 "$FreeBSD: head/usr.sbin/lpr/common_source/net.c 78146 2001-06-12 16:38:20Z gad $";
44#endif /* not lint */
45
46#include <sys/param.h>
47#include <sys/socket.h>
48#include <sys/stat.h>
49#include <sys/time.h>
50#include <sys/uio.h>
51

--- 121 unchanged lines hidden (view full) ---

173 * old method (comparing the canonical names), as it
174 * allows load-sharing between multiple print servers.
175 * The return value is an error message which must be
176 * free()d.
177 */
178char *
179checkremote(struct printer *pp)
180{
44#endif /* not lint */
45
46#include <sys/param.h>
47#include <sys/socket.h>
48#include <sys/stat.h>
49#include <sys/time.h>
50#include <sys/uio.h>
51

--- 121 unchanged lines hidden (view full) ---

173 * old method (comparing the canonical names), as it
174 * allows load-sharing between multiple print servers.
175 * The return value is an error message which must be
176 * free()d.
177 */
178char *
179checkremote(struct printer *pp)
180{
181 char name[MAXHOSTNAMELEN];
181 char lclhost[MAXHOSTNAMELEN];
182 struct addrinfo hints, *local_res, *remote_res, *lr, *rr;
183 char *err;
184 int ncommonaddrs, error;
185 char h1[NI_MAXHOST], h2[NI_MAXHOST];
186
187 if (!pp->rp_matches_local) { /* Remote printer doesn't match local */
188 pp->remote = 1;
189 return NULL;
190 }
191
192 pp->remote = 0; /* assume printer is local */
193 if (pp->remote_host == NULL)
194 return NULL;
195
196 /* get the addresses of the local host */
182 struct addrinfo hints, *local_res, *remote_res, *lr, *rr;
183 char *err;
184 int ncommonaddrs, error;
185 char h1[NI_MAXHOST], h2[NI_MAXHOST];
186
187 if (!pp->rp_matches_local) { /* Remote printer doesn't match local */
188 pp->remote = 1;
189 return NULL;
190 }
191
192 pp->remote = 0; /* assume printer is local */
193 if (pp->remote_host == NULL)
194 return NULL;
195
196 /* get the addresses of the local host */
197 gethostname(name, sizeof(name));
198 name[sizeof(name) - 1] = '\0';
197 gethostname(lclhost, sizeof(lclhost));
198 lclhost[sizeof(lclhost) - 1] = '\0';
199
200 memset(&hints, 0, sizeof(hints));
201 hints.ai_family = family;
202 hints.ai_socktype = SOCK_STREAM;
203 hints.ai_flags = AI_PASSIVE;
199
200 memset(&hints, 0, sizeof(hints));
201 hints.ai_family = family;
202 hints.ai_socktype = SOCK_STREAM;
203 hints.ai_flags = AI_PASSIVE;
204 if ((error = getaddrinfo(name, NULL, &hints, &local_res)) != 0) {
204 if ((error = getaddrinfo(lclhost, NULL, &hints, &local_res)) != 0) {
205 asprintf(&err, "unable to get official name "
206 "for local machine %s: %s",
205 asprintf(&err, "unable to get official name "
206 "for local machine %s: %s",
207 name, gai_strerror(error));
207 lclhost, gai_strerror(error));
208 return err;
209 }
210
211 /* get the official name of RM */
212 memset(&hints, 0, sizeof(hints));
213 hints.ai_family = family;
214 hints.ai_socktype = SOCK_STREAM;
215 hints.ai_flags = AI_PASSIVE;

--- 35 unchanged lines hidden (view full) ---

251}
252
253/*
254 * This isn't really network-related, but it's used here to write
255 * multi-part strings onto sockets without using stdio. Return
256 * values are as for writev(2).
257 */
258ssize_t
208 return err;
209 }
210
211 /* get the official name of RM */
212 memset(&hints, 0, sizeof(hints));
213 hints.ai_family = family;
214 hints.ai_socktype = SOCK_STREAM;
215 hints.ai_flags = AI_PASSIVE;

--- 35 unchanged lines hidden (view full) ---

251}
252
253/*
254 * This isn't really network-related, but it's used here to write
255 * multi-part strings onto sockets without using stdio. Return
256 * values are as for writev(2).
257 */
258ssize_t
259writel(int s, ...)
259writel(int strm, ...)
260{
261 va_list ap;
262 int i, n;
263 const char *cp;
264#define NIOV 12
265 struct iovec iov[NIOV], *iovp = iov;
266 ssize_t retval;
267
268 /* first count them */
260{
261 va_list ap;
262 int i, n;
263 const char *cp;
264#define NIOV 12
265 struct iovec iov[NIOV], *iovp = iov;
266 ssize_t retval;
267
268 /* first count them */
269 va_start(ap, s);
269 va_start(ap, strm);
270 n = 0;
271 do {
272 cp = va_arg(ap, char *);
273 n++;
274 } while (cp);
275 va_end(ap);
276 n--; /* correct for count of trailing null */
277
278 if (n > NIOV) {
279 iovp = malloc(n * sizeof *iovp);
280 if (iovp == 0)
281 return -1;
282 }
283
284 /* now make up iovec and send */
270 n = 0;
271 do {
272 cp = va_arg(ap, char *);
273 n++;
274 } while (cp);
275 va_end(ap);
276 n--; /* correct for count of trailing null */
277
278 if (n > NIOV) {
279 iovp = malloc(n * sizeof *iovp);
280 if (iovp == 0)
281 return -1;
282 }
283
284 /* now make up iovec and send */
285 va_start(ap, s);
285 va_start(ap, strm);
286 for (i = 0; i < n; i++) {
287 iovp[i].iov_base = va_arg(ap, char *);
288 iovp[i].iov_len = strlen(iovp[i].iov_base);
289 }
290 va_end(ap);
286 for (i = 0; i < n; i++) {
287 iovp[i].iov_base = va_arg(ap, char *);
288 iovp[i].iov_len = strlen(iovp[i].iov_base);
289 }
290 va_end(ap);
291 retval = writev(s, iovp, n);
291 retval = writev(strm, iovp, n);
292 if (iovp != iov)
293 free(iovp);
294 return retval;
295}
292 if (iovp != iov)
293 free(iovp);
294 return retval;
295}