Skip to content

Commit

Permalink
Merge r28016 from nmap-npingchanges: Add method to set IP options fro…
Browse files Browse the repository at this point in the history
…m a binary buffer than can be inserted right away into the IP header.
  • Loading branch information
luis committed Mar 29, 2013
1 parent a3f84c2 commit 347badd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
18 changes: 14 additions & 4 deletions libnetutil/IPv4Header.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
/* This code was originally part of the Nping tool. */

#include "IPv4Header.h"
#include <assert.h>

/******************************************************************************/
/* CONTRUCTORS, DESTRUCTORS AND INITIALIZATION METHODS */
Expand Down Expand Up @@ -623,15 +624,24 @@ int IPv4Header::setOpts(const char *txt){
return OP_FAILURE;
}else{
/* Copy options to our IP header */
memcpy(h.options, buffer, ret);
this->ipoptlen=ret;
this->length += ret;
this->setHeaderLength();
this->setOpts(buffer, ret);
}
return OP_SUCCESS;
} /* End of setOpts() */


int IPv4Header::setOpts(u8 *opts_buff, u32 opts_len){
if(opts_buff==NULL || opts_len==0)
return OP_FAILURE;
assert(opts_len<=MAX_IP_OPTIONS_LEN); /* Max lenght for IP options */
memcpy(this->h.options, opts_buff, opts_len);
this->ipoptlen=opts_len;
this->length += opts_len;
this->setHeaderLength();
return OP_SUCCESS;
} /* End of setOpts() */


const u8 *IPv4Header::getOpts() const {
return h.options;
} /* End of getOpts() */
Expand Down
1 change: 1 addition & 0 deletions libnetutil/IPv4Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class IPv4Header : public NetworkLayerElement {

/* IP Options */
int setOpts(const char *txt);
int setOpts(u8 *opts_buff, u32 opts_len);
const u8 *getOpts() const;
const u8 *getOpts(int *len) const;
int printOptions() const;
Expand Down

0 comments on commit 347badd

Please sign in to comment.