- 
                Notifications
    You must be signed in to change notification settings 
- Fork 165
Add Dhcp-Support #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            vbBerni
  wants to merge
  19
  commits into
  PcapDotNet:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
vbBerni:dhcp
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Add Dhcp-Support #84
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            19 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      49164e4
              
                add extension to create a random c-strings
              
              
                vbBerni d2faae8
              
                add dhcp support
              
              
                vbBerni 69ea914
              
                finish dhcp-support with documentation and fixes
              
              
                vbBerni 0e40921
              
                don't use a random invalid port
              
              
                vbBerni 7971a20
              
                TransactionId type int --> uint
              
              
                vbBerni df7dcd2
              
                rename pos --> offset
              
              
                vbBerni 2912854
              
                Avoid using "this." explicitly.
              
              
                vbBerni 5170fe1
              
                change method order public, internal, private
              
              
                vbBerni 3ccd7fc
              
                remove useless overwrite
              
              
                vbBerni 7e1df41
              
                End comments with periods.
              
              
                vbBerni ae3f79c
              
                Replace "true if" with "Whether"
              
              
                vbBerni c1550dd
              
                DHCP_MAGIC_COOKIE int --> uint
              
              
                vbBerni 41bc492
              
                Be consistent with the name - either "op" or "messageType".
              
              
                vbBerni a0d8c6d
              
                fix compilation
              
              
                vbBerni 8b2f118
              
                Consider also writing the null termination.
              
              
                vbBerni f10975f
              
                Replace "RFCs" with "RFC".
              
              
                vbBerni 8a31f33
              
                Instead of having a field for "flags", split it to the different flag…
              
              
                vbBerni 6d0b4dd
              
                using registration mechanism for the options
              
              
                vbBerni cda7273
              
                set HardwareAddressLength when setting setting ClientMacAddress
              
              
                vbBerni File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -9,6 +9,7 @@ | |
| using System.Xml.Linq; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using PcapDotNet.Packets; | ||
| using PcapDotNet.Packets.Dhcp; | ||
| using PcapDotNet.Packets.Dns; | ||
| using PcapDotNet.Packets.Ethernet; | ||
| using PcapDotNet.Packets.Gre; | ||
|  | @@ -390,24 +391,53 @@ private static void CreateRandomIpPayload(Random random, Layer ipLayer, List<ILa | |
| } | ||
| } | ||
|  | ||
| private static void CreateRandomUdpPayload(Random random, UdpLayer udpLayer, List<ILayer> layers) | ||
| { | ||
| if (random.NextBool(20)) | ||
| { | ||
| // Finish with payload. | ||
| PayloadLayer payloadLayer = random.NextPayloadLayer(random.Next(100)); | ||
| layers.Add(payloadLayer); | ||
| return; | ||
| } | ||
|  | ||
| DnsLayer dnsLayer = random.NextDnsLayer(); | ||
| layers.Add(dnsLayer); | ||
|  | ||
| ushort specialPort = (ushort)(random.NextBool() ? 53 : 5355); | ||
| if (dnsLayer.IsQuery) | ||
| udpLayer.DestinationPort = specialPort; | ||
| else | ||
| udpLayer.SourcePort = specialPort; | ||
| private static void CreateRandomUdpPayload(Random random, UdpLayer udpLayer, List<ILayer> layers) | ||
| { | ||
| if (random.NextBool(20)) | ||
| { | ||
| // Finish with payload. | ||
| PayloadLayer payloadLayer = random.NextPayloadLayer(random.Next(100)); | ||
| layers.Add(payloadLayer); | ||
| return; | ||
| } | ||
|  | ||
| switch (random.Next(0, 2)) | ||
| { | ||
| case 0: | ||
| { | ||
| DnsLayer dnsLayer = random.NextDnsLayer(); | ||
| layers.Add(dnsLayer); | ||
|  | ||
| ushort specialPort = (ushort)(random.NextBool() ? 53 : 5355); | ||
| if (dnsLayer.IsQuery) | ||
| udpLayer.DestinationPort = specialPort; | ||
| else | ||
| udpLayer.SourcePort = specialPort; | ||
| break; | ||
| } | ||
|  | ||
| case 1: | ||
| { | ||
| DhcpLayer dhcpLayer = random.NextDhcpLayer(); | ||
| layers.Add(dhcpLayer); | ||
|  | ||
| if (random.NextBool()) | ||
| { | ||
| udpLayer.SourcePort = 67 ; | ||
| udpLayer.DestinationPort = 68; | ||
| } | ||
| else | ||
| { | ||
| udpLayer.SourcePort = 68; | ||
| udpLayer.DestinationPort = 67; | ||
| } | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines 432-439 seem to repeat lines 424-431. | ||
|  | ||
| break; | ||
| } | ||
|  | ||
| default: | ||
| throw new InvalidOperationException("Invalid value."); | ||
| } | ||
| } | ||
|  | ||
| private static void CreateRandomTcpPayload(Random random, TcpLayer tcpLayer, List<ILayer> layers) | ||
|  | ||
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this random.NextBool() instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would keep it because there may be more than two possible payloads in the future