home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / fragrouter / Libnet-0.99b / src / socket.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-26  |  2.3 KB  |  78 lines

  1. /*
  2.  *  $Id: socket.c,v 1.1.1.1 1999/05/18 15:33:42 dugsong Exp $
  3.  *
  4.  *  libnet
  5.  *  socket.c - opens a raw socket of type `prot` and sets the IP_HDRINCL
  6.  *  socket option
  7.  *
  8.  *  Copyright (c) 1998, 1999 Mike D. Schiffman <mike@infonexus.com>
  9.  *                           route|daemon9 <route@infonexus.com>
  10.  *  All rights reserved.
  11.  *
  12.  * Redistribution and use in source and binary forms, with or without
  13.  * modification, are permitted provided that the following conditions
  14.  * are met:
  15.  * 1. Redistributions of source code must retain the above copyright
  16.  *    notice, this list of conditions and the following disclaimer.
  17.  * 2. Redistributions in binary form must reproduce the above copyright
  18.  *    notice, this list of conditions and the following disclaimer in the
  19.  *    documentation and/or other materials provided with the distribution.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  */
  34.  
  35. #if (HAVE_CONFIG_H)
  36. #include "../include/config.h"
  37. #endif
  38. #include "../include/libnet.h"
  39.  
  40. int
  41. open_raw_sock(prot)
  42. {
  43.     int fd;
  44.     int one = 1;
  45. #if (__svr4__)
  46.     void *oneptr = &one;
  47. #else
  48.     int *oneptr = &one;
  49. #endif  /* __svr4__ */
  50.  
  51.     fd = socket(AF_INET, SOCK_RAW, prot);
  52.     if (fd == -1)
  53.     {
  54. #if (__DEBUG)
  55.         fprintf(stderr, "open_raw_sock: SOCK_RAW allocation: %s\n",
  56.             strerror(errno));
  57. #endif
  58.         return (-1);
  59.     }
  60.     if (setsockopt(fd, IPPROTO_IP, IP_HDRINCL, oneptr, sizeof(one)) == -1)
  61.     {
  62. #if (__DEBUG)
  63.         fprintf(stderr, "open_raw_sock: setting IP_HDRINCL: %s\n",
  64.             strerror(errno));
  65. #endif
  66.         return (-1);
  67.     }
  68.     return (fd);
  69. }
  70.  
  71.  
  72. int
  73. close_raw_sock(int fd)
  74. {
  75.     return (close(fd));
  76. }
  77. /* EOF */
  78.