Deleted Added
full compact
ypldap_dns.c (292270) ypldap_dns.c (297907)
1/* $OpenBSD: ypldap_dns.c,v 1.8 2015/01/16 06:40:22 deraadt Exp $ */
1/* $OpenBSD: ypldap_dns.c,v 1.8 2015/01/16 06:40:22 deraadt Exp $ */
2/* $FreeBSD: head/usr.sbin/ypldap/ypldap_dns.c 292270 2015-12-15 15:37:58Z araujo $ */
2/* $FreeBSD: head/usr.sbin/ypldap/ypldap_dns.c 297907 2016-04-13 03:36:34Z araujo $ */
3
4/*
5 * Copyright (c) 2003-2008 Henning Brauer <henning@openbsd.org>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *

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

43#include "ypldap.h"
44
45volatile sig_atomic_t quit_dns = 0;
46struct imsgev *iev_dns;
47
48void dns_dispatch_imsg(int, short, void *);
49void dns_sig_handler(int, short, void *);
50void dns_shutdown(void);
3
4/*
5 * Copyright (c) 2003-2008 Henning Brauer <henning@openbsd.org>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *

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

43#include "ypldap.h"
44
45volatile sig_atomic_t quit_dns = 0;
46struct imsgev *iev_dns;
47
48void dns_dispatch_imsg(int, short, void *);
49void dns_sig_handler(int, short, void *);
50void dns_shutdown(void);
51int host_dns(const char *s, struct ypldap_addr **hn);
51int host_dns(const char *, struct ypldap_addr_list *);
52
53void
54dns_sig_handler(int sig, short event, void *p)
55{
56 switch (sig) {
57 case SIGINT:
58 case SIGTERM:
59 dns_shutdown();

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

124}
125
126void
127dns_dispatch_imsg(int fd, short events, void *p)
128{
129 struct imsg imsg;
130 int n, cnt;
131 char *name;
52
53void
54dns_sig_handler(int sig, short event, void *p)
55{
56 switch (sig) {
57 case SIGINT:
58 case SIGTERM:
59 dns_shutdown();

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

124}
125
126void
127dns_dispatch_imsg(int fd, short events, void *p)
128{
129 struct imsg imsg;
130 int n, cnt;
131 char *name;
132 struct ypldap_addr *h, *hn;
132 struct ypldap_addr_list hn = TAILQ_HEAD_INITIALIZER(hn);
133 struct ypldap_addr *h;
133 struct ibuf *buf;
134 struct env *env = p;
135 struct imsgev *iev = env->sc_iev;
136 struct imsgbuf *ibuf = &iev->ibuf;
137 int shut = 0;
138
139 if ((events & (EV_READ | EV_WRITE)) == 0)
140 fatalx("unknown event");

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

171 if ((cnt = host_dns(name, &hn)) == -1)
172 break;
173 buf = imsg_create(ibuf, IMSG_HOST_DNS,
174 imsg.hdr.peerid, 0,
175 cnt * sizeof(struct sockaddr_storage));
176 if (buf == NULL)
177 break;
178 if (cnt > 0) {
134 struct ibuf *buf;
135 struct env *env = p;
136 struct imsgev *iev = env->sc_iev;
137 struct imsgbuf *ibuf = &iev->ibuf;
138 int shut = 0;
139
140 if ((events & (EV_READ | EV_WRITE)) == 0)
141 fatalx("unknown event");

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

172 if ((cnt = host_dns(name, &hn)) == -1)
173 break;
174 buf = imsg_create(ibuf, IMSG_HOST_DNS,
175 imsg.hdr.peerid, 0,
176 cnt * sizeof(struct sockaddr_storage));
177 if (buf == NULL)
178 break;
179 if (cnt > 0) {
179 h = hn;
180 while (h != NULL) {
180 while(!TAILQ_EMPTY(&hn)) {
181 h = TAILQ_FIRST(&hn);
182 TAILQ_REMOVE(&hn, h, next);
181 imsg_add(buf, &h->ss, sizeof(h->ss));
183 imsg_add(buf, &h->ss, sizeof(h->ss));
182 hn = h->next;
183 free(h);
184 free(h);
184 h = hn;
185 }
186 }
187
188 imsg_close(ibuf, buf);
189 break;
190 default:
191 break;
192 }

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

199 else {
200 /* this pipe is dead, so remove the event handler */
201 event_del(&iev->ev);
202 event_loopexit(NULL);
203 }
204}
205
206int
185 }
186 }
187
188 imsg_close(ibuf, buf);
189 break;
190 default:
191 break;
192 }

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

199 else {
200 /* this pipe is dead, so remove the event handler */
201 event_del(&iev->ev);
202 event_loopexit(NULL);
203 }
204}
205
206int
207host_dns(const char *s, struct ypldap_addr **hn)
207host_dns(const char *s, struct ypldap_addr_list *hn)
208{
209 struct addrinfo hints, *res0, *res;
210 int error, cnt = 0;
211 struct sockaddr_in *sa_in;
212 struct sockaddr_in6 *sa_in6;
208{
209 struct addrinfo hints, *res0, *res;
210 int error, cnt = 0;
211 struct sockaddr_in *sa_in;
212 struct sockaddr_in6 *sa_in6;
213 struct ypldap_addr *h, *hh = NULL;
213 struct ypldap_addr *h;
214
215 bzero(&hints, sizeof(hints));
216 hints.ai_family = PF_UNSPEC;
217 hints.ai_socktype = SOCK_DGRAM; /* DUMMY */
218 error = getaddrinfo(s, NULL, &hints, &res0);
219 if (error == EAI_AGAIN || error == EAI_NONAME)
220 return (0);
221 if (error) {

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

238 res->ai_addr)->sin_addr.s_addr;
239 } else {
240 sa_in6 = (struct sockaddr_in6 *)&h->ss;
241 sa_in6->sin6_len = sizeof(struct sockaddr_in6);
242 memcpy(&sa_in6->sin6_addr, &((struct sockaddr_in6 *)
243 res->ai_addr)->sin6_addr, sizeof(struct in6_addr));
244 }
245
214
215 bzero(&hints, sizeof(hints));
216 hints.ai_family = PF_UNSPEC;
217 hints.ai_socktype = SOCK_DGRAM; /* DUMMY */
218 error = getaddrinfo(s, NULL, &hints, &res0);
219 if (error == EAI_AGAIN || error == EAI_NONAME)
220 return (0);
221 if (error) {

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

238 res->ai_addr)->sin_addr.s_addr;
239 } else {
240 sa_in6 = (struct sockaddr_in6 *)&h->ss;
241 sa_in6->sin6_len = sizeof(struct sockaddr_in6);
242 memcpy(&sa_in6->sin6_addr, &((struct sockaddr_in6 *)
243 res->ai_addr)->sin6_addr, sizeof(struct in6_addr));
244 }
245
246 h->next = hh;
247 hh = h;
246 TAILQ_INSERT_HEAD(hn, h, next);
248 cnt++;
249 }
250 freeaddrinfo(res0);
247 cnt++;
248 }
249 freeaddrinfo(res0);
251
252 *hn = hh;
253 return (cnt);
254}
250 return (cnt);
251}