Diff for /embedaddon/libnet/src/libnet_init.c between versions 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 2012/02/21 22:14:23 version 1.1.1.2, 2013/07/22 11:54:42
Line 40 Line 40
 #endif  #endif
   
 libnet_t *  libnet_t *
libnet_init(int injection_type, char *device, char *err_buf)libnet_init(int injection_type, const char *device, char *err_buf)
 {  {
     libnet_t *l = NULL;      libnet_t *l = NULL;
   
#if !defined(__WIN32__)#if defined(__WIN32__)
    if (getuid() && geteuid()) 
    { 
        snprintf(err_buf, LIBNET_ERRBUF_SIZE, 
                "%s(): UID or EUID of 0 required\n", __func__); 
        goto bad; 
    } 
#else 
     WSADATA wsaData;      WSADATA wsaData;
   
     if ((WSAStartup(0x0202, &wsaData)) != 0)      if ((WSAStartup(0x0202, &wsaData)) != 0)
Line 75  libnet_init(int injection_type, char *device, char *er Line 68  libnet_init(int injection_type, char *device, char *er
     l->injection_type   = injection_type;      l->injection_type   = injection_type;
     l->ptag_state       = LIBNET_PTAG_INITIALIZER;      l->ptag_state       = LIBNET_PTAG_INITIALIZER;
     l->device           = (device ? strdup(device) : NULL);      l->device           = (device ? strdup(device) : NULL);
       l->fd               = -1;
   
     strncpy(l->label, LIBNET_LABEL_DEFAULT, LIBNET_LABEL_SIZE);      strncpy(l->label, LIBNET_LABEL_DEFAULT, LIBNET_LABEL_SIZE);
    l->label[sizeof(l->label)] = '\0';    l->label[LIBNET_LABEL_SIZE - 1] = '\0';
   
     switch (l->injection_type)      switch (l->injection_type)
     {      {
           case LIBNET_NONE:
               break;
         case LIBNET_LINK:          case LIBNET_LINK:
         case LIBNET_LINK_ADV:          case LIBNET_LINK_ADV:
             if (libnet_select_device(l) == -1)              if (libnet_select_device(l) == -1)
             {              {
                snprintf(err_buf, LIBNET_ERRBUF_SIZE, l->err_buf);                snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s", l->err_buf);
                 goto bad;                  goto bad;
             }              }
             if (libnet_open_link(l) == -1)              if (libnet_open_link(l) == -1)
             {              {
                snprintf(err_buf, LIBNET_ERRBUF_SIZE, l->err_buf);                snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s", l->err_buf);
                 goto bad;                  goto bad;
             }              }
             break;              break;
Line 98  libnet_init(int injection_type, char *device, char *er Line 94  libnet_init(int injection_type, char *device, char *er
         case LIBNET_RAW4_ADV:          case LIBNET_RAW4_ADV:
             if (libnet_open_raw4(l) == -1)              if (libnet_open_raw4(l) == -1)
             {              {
                snprintf(err_buf, LIBNET_ERRBUF_SIZE, l->err_buf);                snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s", l->err_buf);
                 goto bad;                  goto bad;
             }              }
             break;              break;
Line 106  libnet_init(int injection_type, char *device, char *er Line 102  libnet_init(int injection_type, char *device, char *er
         case LIBNET_RAW6_ADV:          case LIBNET_RAW6_ADV:
             if (libnet_open_raw6(l) == -1)              if (libnet_open_raw6(l) == -1)
             {              {
                snprintf(err_buf, LIBNET_ERRBUF_SIZE, l->err_buf);                snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s", l->err_buf);
                 goto bad;                  goto bad;
             }              }
             break;              break;
Line 133  libnet_destroy(libnet_t *l) Line 129  libnet_destroy(libnet_t *l)
     if (l)      if (l)
     {      {
         close(l->fd);          close(l->fd);
        if (l->device)        free(l->device);
        { 
            free(l->device); 
        } 
         libnet_clear_packet(l);          libnet_clear_packet(l);
         free(l);          free(l);
     }      }
Line 146  void Line 139  void
 libnet_clear_packet(libnet_t *l)  libnet_clear_packet(libnet_t *l)
 {  {
     libnet_pblock_t *p;      libnet_pblock_t *p;
     libnet_pblock_t *next;  
   
    if (l)    if (!l)
     {      {
        p = l->protocol_blocks;        return;
        if (p) 
        { 
            for (; p; p = next) 
            { 
                next = p->next; 
                if (p->buf) 
                { 
                    free(p->buf); 
                } 
                free(p); 
            } 
        } 
        l->protocol_blocks = NULL; 
        l->total_size = 0; 
     }      }
   
       while((p = l->protocol_blocks))
       {
           libnet_pblock_delete(l, p);
       }
   
       /* All pblocks are deleted, so start the tag count over from 1. */
       l->ptag_state = 0;
 }  }
   
 void  void
Line 192  libnet_getfd(libnet_t *l) Line 178  libnet_getfd(libnet_t *l)
     return (l->fd);      return (l->fd);
 }  }
   
int8_t *const char *
 libnet_getdevice(libnet_t *l)  libnet_getdevice(libnet_t *l)
 {  {
     if (l == NULL)      if (l == NULL)
Line 203  libnet_getdevice(libnet_t *l) Line 189  libnet_getdevice(libnet_t *l)
     return (l->device);      return (l->device);
 }  }
   
u_int8_t *uint8_t *
 libnet_getpbuf(libnet_t *l, libnet_ptag_t ptag)  libnet_getpbuf(libnet_t *l, libnet_ptag_t ptag)
 {  {
     libnet_pblock_t *p;      libnet_pblock_t *p;
Line 225  libnet_getpbuf(libnet_t *l, libnet_ptag_t ptag) Line 211  libnet_getpbuf(libnet_t *l, libnet_ptag_t ptag)
     }      }
 }  }
   
u_int32_tuint32_t
 libnet_getpbuf_size(libnet_t *l, libnet_ptag_t ptag)  libnet_getpbuf_size(libnet_t *l, libnet_ptag_t ptag)
 {  {
     libnet_pblock_t *p;      libnet_pblock_t *p;
Line 247  libnet_getpbuf_size(libnet_t *l, libnet_ptag_t ptag) Line 233  libnet_getpbuf_size(libnet_t *l, libnet_ptag_t ptag)
     }      }
 }  }
   
u_int32_tuint32_t
 libnet_getpacket_size(libnet_t *l)  libnet_getpacket_size(libnet_t *l)
 {  {
       /* Why doesn't this return l->total_size? */
     libnet_pblock_t *p;      libnet_pblock_t *p;
    u_int32_t n;    uint32_t n;
   
     if (l == NULL)      if (l == NULL)
     {       { 

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>