SpoofDPI/util/util.go

67 lines
949 B
Go
Raw Normal View History

2021-12-29 17:08:30 +00:00
package util
import (
2022-01-03 07:24:39 +00:00
"log"
"strings"
"github.com/xvzc/SpoofDPI/config"
2021-12-29 17:08:30 +00:00
)
2022-01-07 13:44:03 +00:00
func ExtractDomain(message *[]byte) string {
i := 0
for ; i < len(*message); i++ {
if (*message)[i] == '\n' {
i++
break
}
}
for ; i < len(*message); i++ {
if (*message)[i] == ' ' {
i++
break
}
}
j := i
for ; j < len(*message); j++ {
if (*message)[j] == '\n' {
break
}
}
domain := strings.Split(string((*message)[i:j]), ":")[0]
return strings.TrimSpace(domain)
2021-12-29 17:08:30 +00:00
}
2022-01-07 13:44:03 +00:00
func ExtractMethod(message *[]byte) string {
i := 0
for ; i < len(*message); i++ {
if (*message)[i] == ' ' {
break
}
}
2021-12-29 17:08:30 +00:00
2022-01-07 13:44:03 +00:00
method := strings.TrimSpace(string((*message)[:i]))
Debug(method)
2021-12-29 17:08:30 +00:00
2022-01-07 13:44:03 +00:00
return strings.ToUpper(method)
2021-12-29 17:08:30 +00:00
}
2022-01-03 07:24:39 +00:00
func Debug(v ...interface{}) {
2022-01-07 13:44:03 +00:00
if config.GetConfig().Debug == false {
return
}
2022-01-03 07:24:39 +00:00
2022-01-07 13:44:03 +00:00
log.Println(v...)
2022-01-03 07:24:39 +00:00
}
2022-01-03 15:13:42 +00:00
2022-01-07 13:44:03 +00:00
func BytesToChunks(buf []byte) [][]byte {
if len(buf) < 1 {
return [][]byte{buf}
}
2022-01-03 15:13:42 +00:00
2022-01-07 13:44:03 +00:00
return [][]byte{buf[:1], buf[1:]}
2022-01-03 15:13:42 +00:00
}