Skip to content

Commit

Permalink
add function headers
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalcaliskan committed Jan 1, 2022
1 parent 3b26f47 commit f850233
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func Execute() {
}
}

// init function initializes the cmd module
func init() {
opts := options.GetSynFloodOptions()

Expand Down
1 change: 0 additions & 1 deletion internal/raw/raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func TestStartFlooding(t *testing.T) {
{"500byte_syn", "syn", 500, srcPorts[rand.Intn(len(srcPorts))], 443, 100,
srcIps[rand.Intn(len(srcIps))], "213.238.175.187",
macAddrs[rand.Intn(len(macAddrs))], macAddrs[rand.Intn(len(macAddrs))]},
// TODO: other cases like floodType=ack, floodType=synAck. think a solution to "too many open files" error ;)
}

for _, tc := range cases {
Expand Down
7 changes: 7 additions & 0 deletions internal/raw/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (
"regexp"
)

// getRandomPayload returns a byte slice to spoof ip packets with random payload in specified length
func getRandomPayload(length int) []byte {
payload := make([]byte, length)
rand.Read(payload)
return payload
}

// getIps returns a string slice to spoof ip packets with dummy source ip addresses
func getIps() []string {
ips := make([]string, 0)
for i := 0; i < 20; i++ {
Expand All @@ -25,6 +27,7 @@ func getIps() []string {
return ips
}

// getPorts returns an int slice to spoof ip packets with dummy source ports
func getPorts() []int {
ports := make([]int, 0)
for i := 1024; i <= 65535; i++ {
Expand All @@ -34,6 +37,7 @@ func getPorts() []int {
return ports
}

// getMacAddrs returns a byte slice to spoof ip packets with dummy MAC addresses
func getMacAddrs() [][]byte {
macAddrs := make([][]byte, 0)
for i := 0; i <= 50; i++ {
Expand All @@ -49,6 +53,7 @@ func getMacAddrs() [][]byte {
return macAddrs
}

// isDNS returns a boolean which indicates host parameter is a DNS record or not
func isDNS(host string) bool {
var (
res bool
Expand All @@ -62,6 +67,7 @@ func isDNS(host string) bool {
return res
}

// isIP returns a boolean which indicates host parameter is an IP address or not
func isIP(host string) bool {
var (
res bool
Expand All @@ -75,6 +81,7 @@ func isIP(host string) bool {
return res
}

// resolveHost function gets a string and returns the ip address while deciding it is an ip address already or DNS record
func resolveHost(host string) string {
if !isIP(host) && isDNS(host) {
log.Printf("%s is a DNS record, making DNS lookup\n", host)
Expand Down

0 comments on commit f850233

Please sign in to comment.