Deleted Added
full compact
sock.c (153881) sock.c (161357)
1/* $FreeBSD: head/contrib/ipfilter/ipsend/sock.c 153881 2005-12-30 11:52:26Z guido $ */
1/* $FreeBSD: head/contrib/ipfilter/ipsend/sock.c 161357 2006-08-16 12:23:02Z guido $ */
2/*
3 * sock.c (C) 1995-1998 Darren Reed
4 *
5 * See the IPFILTER.LICENCE file for details on licencing.
6 *
7 */
8#if !defined(lint)
9static const char sccsid[] = "@(#)sock.c 1.2 1/11/96 (C)1995 Darren Reed";
2/*
3 * sock.c (C) 1995-1998 Darren Reed
4 *
5 * See the IPFILTER.LICENCE file for details on licencing.
6 *
7 */
8#if !defined(lint)
9static const char sccsid[] = "@(#)sock.c 1.2 1/11/96 (C)1995 Darren Reed";
10static const char rcsid[] = "@(#)$Id: sock.c,v 2.8.4.1 2004/03/23 12:58:06 darrenr Exp $";
10static const char rcsid[] = "@(#)$Id: sock.c,v 2.8.4.4 2006/03/21 16:10:56 darrenr Exp $";
11#endif
12#include <sys/param.h>
13#include <sys/types.h>
14#include <sys/time.h>
15#include <sys/stat.h>
11#endif
12#include <sys/param.h>
13#include <sys/types.h>
14#include <sys/time.h>
15#include <sys/stat.h>
16#if defined(__NetBSD__) && defined(__vax__)
17/*
18 * XXX need to declare boolean_t for _KERNEL <sys/files.h>
19 * which ends up including <sys/device.h> for vax. See PR#32907
20 * for further details.
21 */
22typedef int boolean_t;
23#endif
16#ifndef ultrix
17#include <fcntl.h>
18#endif
19#if (__FreeBSD_version >= 300000)
20# include <sys/dirent.h>
21#else
22# include <sys/dir.h>
23#endif

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

297 if (KMCPY(fd, p->kp_proc.p_fd, sizeof(*fd)) == -1)
298 {
299 fprintf(stderr, "read(%#lx,%#lx) failed\n",
300 (u_long)p, (u_long)p->kp_proc.p_fd);
301 return NULL;
302 }
303#endif
304
24#ifndef ultrix
25#include <fcntl.h>
26#endif
27#if (__FreeBSD_version >= 300000)
28# include <sys/dirent.h>
29#else
30# include <sys/dir.h>
31#endif

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

305 if (KMCPY(fd, p->kp_proc.p_fd, sizeof(*fd)) == -1)
306 {
307 fprintf(stderr, "read(%#lx,%#lx) failed\n",
308 (u_long)p, (u_long)p->kp_proc.p_fd);
309 return NULL;
310 }
311#endif
312
313 o = NULL;
314 f = NULL;
315 s = NULL;
316 i = NULL;
317 t = NULL;
318
305 o = (struct file **)calloc(1, sizeof(*o) * (fd->fd_lastfile + 1));
306 if (KMCPY(o, fd->fd_ofiles, (fd->fd_lastfile + 1) * sizeof(*o)) == -1)
307 {
308 fprintf(stderr, "read(%#lx,%#lx,%lu) - u_ofile - failed\n",
309 (u_long)fd->fd_ofiles, (u_long)o, (u_long)sizeof(*o));
319 o = (struct file **)calloc(1, sizeof(*o) * (fd->fd_lastfile + 1));
320 if (KMCPY(o, fd->fd_ofiles, (fd->fd_lastfile + 1) * sizeof(*o)) == -1)
321 {
322 fprintf(stderr, "read(%#lx,%#lx,%lu) - u_ofile - failed\n",
323 (u_long)fd->fd_ofiles, (u_long)o, (u_long)sizeof(*o));
310 return NULL;
324 goto finderror;
311 }
312 f = (struct file *)calloc(1, sizeof(*f));
313 if (KMCPY(f, o[tfd], sizeof(*f)) == -1)
314 {
315 fprintf(stderr, "read(%#lx,%#lx,%lu) - o[tfd] - failed\n",
316 (u_long)o[tfd], (u_long)f, (u_long)sizeof(*f));
325 }
326 f = (struct file *)calloc(1, sizeof(*f));
327 if (KMCPY(f, o[tfd], sizeof(*f)) == -1)
328 {
329 fprintf(stderr, "read(%#lx,%#lx,%lu) - o[tfd] - failed\n",
330 (u_long)o[tfd], (u_long)f, (u_long)sizeof(*f));
317 return NULL;
331 goto finderror;
318 }
319
320 s = (struct socket *)calloc(1, sizeof(*s));
321 if (KMCPY(s, f->f_data, sizeof(*s)) == -1)
322 {
323 fprintf(stderr, "read(%#lx,%#lx,%lu) - f_data - failed\n",
332 }
333
334 s = (struct socket *)calloc(1, sizeof(*s));
335 if (KMCPY(s, f->f_data, sizeof(*s)) == -1)
336 {
337 fprintf(stderr, "read(%#lx,%#lx,%lu) - f_data - failed\n",
324 (u_long)f->f_data, (u_long)s,
325 (u_long)sizeof(*s));
326 return NULL;
338 (u_long)f->f_data, (u_long)s, (u_long)sizeof(*s));
339 goto finderror;
327 }
328
329 i = (struct inpcb *)calloc(1, sizeof(*i));
330 if (KMCPY(i, s->so_pcb, sizeof(*i)) == -1)
331 {
332 fprintf(stderr, "kvm_read(%#lx,%#lx,%lu) - so_pcb - failed\n",
333 (u_long)s->so_pcb, (u_long)i, (u_long)sizeof(*i));
340 }
341
342 i = (struct inpcb *)calloc(1, sizeof(*i));
343 if (KMCPY(i, s->so_pcb, sizeof(*i)) == -1)
344 {
345 fprintf(stderr, "kvm_read(%#lx,%#lx,%lu) - so_pcb - failed\n",
346 (u_long)s->so_pcb, (u_long)i, (u_long)sizeof(*i));
334 return NULL;
347 goto finderror;
335 }
336
337 t = (struct tcpcb *)calloc(1, sizeof(*t));
338 if (KMCPY(t, i->inp_ppcb, sizeof(*t)) == -1)
339 {
340 fprintf(stderr, "read(%#lx,%#lx,%lu) - inp_ppcb - failed\n",
341 (u_long)i->inp_ppcb, (u_long)t, (u_long)sizeof(*t));
348 }
349
350 t = (struct tcpcb *)calloc(1, sizeof(*t));
351 if (KMCPY(t, i->inp_ppcb, sizeof(*t)) == -1)
352 {
353 fprintf(stderr, "read(%#lx,%#lx,%lu) - inp_ppcb - failed\n",
354 (u_long)i->inp_ppcb, (u_long)t, (u_long)sizeof(*t));
342 return NULL;
355 goto finderror;
343 }
344 return (struct tcpcb *)i->inp_ppcb;
356 }
357 return (struct tcpcb *)i->inp_ppcb;
358
359finderror:
360 if (o != NULL)
361 free(o);
362 if (f != NULL)
363 free(f);
364 if (s != NULL)
365 free(s);
366 if (i != NULL)
367 free(i);
368 if (t != NULL)
369 free(t);
370 return NULL;
345}
346#endif /* BSD < 199301 */
347
348int do_socket(dev, mtu, ti, gwip)
349char *dev;
350int mtu;
351struct tcpiphdr *ti;
352struct in_addr gwip;

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

378 {
379 perror("bind");
380 return -1;
381 }
382 len = sizeof(lsin);
383 (void) getsockname(fd, (struct sockaddr *)&lsin, &len);
384 ti->ti_sport = lsin.sin_port;
385 printf("sport %d\n", ntohs(lsin.sin_port));
371}
372#endif /* BSD < 199301 */
373
374int do_socket(dev, mtu, ti, gwip)
375char *dev;
376int mtu;
377struct tcpiphdr *ti;
378struct in_addr gwip;

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

404 {
405 perror("bind");
406 return -1;
407 }
408 len = sizeof(lsin);
409 (void) getsockname(fd, (struct sockaddr *)&lsin, &len);
410 ti->ti_sport = lsin.sin_port;
411 printf("sport %d\n", ntohs(lsin.sin_port));
412
386 nfd = initdevice(dev, 1);
413 nfd = initdevice(dev, 1);
414 if (nfd == -1)
415 return -1;
387
388 if (!(t = find_tcp(fd, ti)))
389 return -1;
390
391 bzero((char *)&rsin, sizeof(rsin));
392 rsin.sin_family = AF_INET;
393 bcopy((char *)&ti->ti_dst, (char *)&rsin.sin_addr,
394 sizeof(struct in_addr));

--- 19 unchanged lines hidden ---
416
417 if (!(t = find_tcp(fd, ti)))
418 return -1;
419
420 bzero((char *)&rsin, sizeof(rsin));
421 rsin.sin_family = AF_INET;
422 bcopy((char *)&ti->ti_dst, (char *)&rsin.sin_addr,
423 sizeof(struct in_addr));

--- 19 unchanged lines hidden ---