How to use parseAddr method of prog Package

Best Syzkaller code snippet using prog.parseAddr

vma_call_handlers.go

Source:vma_call_handlers.go Github

copy

Full Screen

1package parser2import (3 //"fmt"4 "github.com/google/syzkaller/prog"5 "github.com/shankarapailoor/moonshine/strace_types"6 "github.com/shankarapailoor/moonshine/tracker"7)8const (9 pageSize = 409610 MapFixed = "MAP_FIXED"11 RemapFixed = "MREMAP_FIXED"12)13func ParseMemoryCall(ctx *Context) *prog.Call {14 syzCall := ctx.CurrentSyzCall15 straceCall := ctx.CurrentStraceCall16 if straceCall.CallName == "mmap" {17 return ParseMmap(syzCall.Meta, straceCall, ctx)18 } else if straceCall.CallName == "mremap" {19 return ParseMremap(syzCall.Meta, straceCall, ctx)20 } else if straceCall.CallName == "msync" {21 return ParseMsync(syzCall.Meta, straceCall, ctx)22 } else if straceCall.CallName == "mprotect" {23 return ParseMprotect(syzCall.Meta, straceCall, ctx)24 } else if straceCall.CallName == "munmap" {25 return ParseMunmap(syzCall.Meta, straceCall, ctx)26 } else if straceCall.CallName == "madvise" {27 return ParseMadvise(syzCall.Meta, straceCall, ctx)28 } else if straceCall.CallName == "mlock" {29 return ParseMlock(syzCall.Meta, straceCall, ctx)30 } else if straceCall.CallName == "munlock" {31 return ParseMunlock(syzCall.Meta, straceCall, ctx)32 } else if straceCall.CallName == "shmat" {33 return ParseShmat(syzCall.Meta, straceCall, ctx)34 }35 return nil36}37func ParseMmap(mmap *prog.Syscall, syscall *strace_types.Syscall, ctx *Context) *prog.Call {38 call := &prog.Call{39 Meta: mmap,40 Ret: strace_types.ReturnArg(mmap.Ret),41 }42 ctx.CurrentSyzCall = call43 length := uint64(0)44 length = ParseLength(syscall.Args[1], ctx)45 length = (length/pageSize + 1)*pageSize46 addrArg, start := ParseAddr(length, mmap.Args[0], syscall.Args[0], ctx)47 lengthArg := prog.MakeConstArg(mmap.Args[1], length)48 protArg := ParseFlags(mmap.Args[2], syscall.Args[2], ctx, false)49 flagArg := ParseFlags(mmap.Args[3], syscall.Args[3], ctx, true)50 fdArg := ParseFd(mmap.Args[4], syscall.Args[4], ctx)51 call.Args = []prog.Arg {52 addrArg,53 lengthArg,54 protArg,55 flagArg,56 fdArg,57 prog.MakeConstArg(mmap.Args[5], 0),58 }59 ctx.State.Tracker.CreateMapping(call, len(ctx.Prog.Calls), call.Args[0], start, start+length) //All mmaps have fixed mappings in syzkaller60 return call61}62func ParseMremap(mremap *prog.Syscall, syscall *strace_types.Syscall, ctx *Context) *prog.Call {63 call := &prog.Call{64 Meta: mremap,65 Ret: strace_types.ReturnArg(mremap.Ret),66 }67 ctx.CurrentSyzCall = call68 oldAddrArg, start := ParseAddr(pageSize, mremap.Args[0], syscall.Args[0], ctx)69 oldSz := ParseLength(syscall.Args[1], ctx)70 newSz := ParseLength(syscall.Args[2], ctx)71 oldSzArg := prog.MakeConstArg(mremap.Args[1], oldSz)72 newSzArg := prog.MakeConstArg(mremap.Args[2], newSz)73 flagArg := ParseFlags(mremap.Args[3], syscall.Args[3], ctx, true)74 var destAddrArg prog.Arg75 var destAddr uint6476 if len(syscall.Args) > 4 {77 destAddrArg, destAddr = ParseAddr(pageSize, mremap.Args[4], syscall.Args[4], ctx)78 } else {79 straceAddrArg := strace_types.NewExpression(strace_types.NewIntType(syscall.Ret))80 destAddrArg, destAddr = ParseAddr(pageSize, mremap.Args[4], straceAddrArg, ctx)81 }82 AddDependency(start, oldSz, oldAddrArg, ctx)83 call.Args = []prog.Arg {84 oldAddrArg,85 oldSzArg,86 newSzArg,87 flagArg,88 destAddrArg,89 }90 ctx.State.Tracker.CreateMapping(call, len(ctx.Prog.Calls), call.Args[4], destAddr, destAddr+newSz) //All mmaps have fixed mappings in syzkaller91 return call92}93func ParseMsync(msync *prog.Syscall, syscall *strace_types.Syscall, ctx *Context) *prog.Call {94 call := &prog.Call{95 Meta: msync,96 Ret: strace_types.ReturnArg(msync.Ret),97 }98 ctx.CurrentSyzCall = call99 addrArg, address := ParseAddr(pageSize, msync.Args[0], syscall.Args[0], ctx)100 length := uint64(0)101 length = ParseLength(syscall.Args[1], ctx)102 lengthArg := prog.MakeConstArg(msync.Args[1], length)103 protArg := ParseFlags(msync.Args[2], syscall.Args[2], ctx, false)104 AddDependency(address, length, addrArg, ctx)105 call.Args = []prog.Arg {106 addrArg,107 lengthArg,108 protArg,109 }110 return call111}112func ParseMprotect(mprotect *prog.Syscall, syscall *strace_types.Syscall, ctx *Context) *prog.Call {113 call := &prog.Call {114 Meta: mprotect,115 Ret: strace_types.ReturnArg(mprotect.Ret),116 }117 ctx.CurrentSyzCall = call118 addrArg, address := ParseAddr(pageSize, mprotect.Args[0], syscall.Args[0], ctx)119 length := ParseLength(syscall.Args[1], ctx)120 lengthArg := prog.MakeConstArg(mprotect.Args[1], length)121 protArg := ParseFlags(mprotect.Args[2], syscall.Args[2], ctx, false)122 AddDependency(address, length, addrArg, ctx)123 call.Args = []prog.Arg {124 addrArg,125 lengthArg,126 protArg,127 }128 return call129}130func ParseMunmap(munmap *prog.Syscall, syscall *strace_types.Syscall, ctx *Context) *prog.Call {131 call := &prog.Call {132 Meta: munmap,133 Ret: strace_types.ReturnArg(munmap.Ret),134 }135 ctx.CurrentSyzCall = call136 addrArg, address := ParseAddr(pageSize, munmap.Args[0], syscall.Args[0], ctx)137 length := ParseLength(syscall.Args[1], ctx)138 lengthArg := prog.MakeConstArg(munmap.Args[1], length)139 AddDependency(address, length, addrArg, ctx)140 call.Args = []prog.Arg{141 addrArg,142 lengthArg,143 }144 return call145}146func ParseMadvise(madvise *prog.Syscall, syscall *strace_types.Syscall, ctx *Context) *prog.Call {147 call := &prog.Call {148 Meta: madvise,149 Ret: strace_types.ReturnArg(madvise.Ret),150 }151 ctx.CurrentSyzCall = call152 addrArg, address := ParseAddr(pageSize, madvise.Args[0], syscall.Args[0], ctx)153 length := ParseLength(syscall.Args[1], ctx)154 lengthArg := prog.MakeConstArg(madvise.Args[1], length)155 var adviceArg prog.Arg156 switch a := syscall.Args[2].(type) {157 case *strace_types.Expression:158 adviceArg = strace_types.ConstArg(madvise.Args[2], a.Eval(ctx.Target))159 default:160 panic("Madvise advice arg is not expression")161 }162 AddDependency(address, length, addrArg, ctx)163 call.Args = []prog.Arg {164 addrArg,165 lengthArg,166 adviceArg,167 }168 return call169}170func ParseMlock(mlock *prog.Syscall, syscall *strace_types.Syscall, ctx *Context) *prog.Call {171 call := &prog.Call {172 Meta: mlock,173 Ret : strace_types.ReturnArg(mlock.Ret),174 }175 ctx.CurrentSyzCall = call176 addrArg, address := ParseAddr(pageSize, mlock.Args[0], syscall.Args[0], ctx)177 length := ParseLength(syscall.Args[1], ctx)178 flagArg := strace_types.ConstArg(mlock.Args[1], length)179 AddDependency(address, length, addrArg, ctx)180 call.Args = []prog.Arg {181 addrArg,182 flagArg,183 }184 return call185}186func ParseMunlock(munlock *prog.Syscall, syscall *strace_types.Syscall, ctx *Context) *prog.Call {187 call := &prog.Call {188 Meta: munlock,189 Ret : strace_types.ReturnArg(munlock.Ret),190 }191 ctx.CurrentSyzCall = call192 addrArg, address := ParseAddr(pageSize, munlock.Args[0], syscall.Args[0], ctx)193 length := ParseLength(syscall.Args[1], ctx)194 flagArg := strace_types.ConstArg(munlock.Args[1], length)195 AddDependency(address, length, addrArg, ctx)196 call.Args = []prog.Arg {197 addrArg,198 flagArg,199 }200 return call201}202func ParseShmat(shmat *prog.Syscall, syscall *strace_types.Syscall, ctx *Context) *prog.Call {203 /*204 * Shmat will create a shared memory map which we should track.205 * If the second argument is NULL then shmat will create the memory map and206 * store it at that address if successful.207 */208 shmid := uint64(0)209 var fd prog.Arg210 call := &prog.Call{211 Meta: shmat,212 Ret: strace_types.ReturnArg(shmat.Ret),213 }214 ctx.CurrentSyzCall = call215 if arg := ctx.Cache.Get(shmat.Args[0], syscall.Args[0]); arg != nil {216 fd = strace_types.ResultArg(shmat.Args[0], arg.(*prog.ResultArg), arg.Type().Default())217 } else {218 switch a := syscall.Args[0].(type) {219 case *strace_types.Expression:220 shmid = a.Eval(ctx.Target)221 default:222 shmid = 0223 }224 fd = strace_types.ResultArg(shmat.Args[0], nil, shmid)225 }226 addrArg, address := ParseAddr(pageSize, shmat.Args[1], syscall.Args[1], ctx)227 flags := ParseFlags(shmat.Args[2], syscall.Args[2], ctx, false)228 call.Args = []prog.Arg{229 fd,230 addrArg,231 flags,232 }233 //Cache the mapped address since it is a resource type as well234 call.Ret = prog.MakeReturnArg(shmat.Ret)235 straceRet := strace_types.NewExpression(strace_types.NewIntType(syscall.Ret))236 ctx.Cache.Cache(call.Ret.Type(), straceRet, call.Ret)237 length := uint64(4096)238 if req := ctx.State.Tracker.FindShmRequest(shmid); req != nil {239 length = req.GetSize()240 }241 ctx.State.Tracker.CreateMapping(call, len(ctx.Prog.Calls), call.Args[1], address, address + length)242 return call243}244func ParseAddr(length uint64, syzType prog.Type, straceType strace_types.Type, ctx *Context) (prog.Arg, uint64){245 defAddrStart := (ctx.Target.NumPages-2)*ctx.Target.PageSize246 switch a := straceType.(type) {247 case *strace_types.PointerType:248 var addrStart uint64249 if a.IsNull() {250 //Anonymous MMAP251 addrStart = uint64(ctx.CurrentStraceCall.Ret)252 return prog.MakeVmaPointerArg(syzType, defAddrStart, length), addrStart253 } else {254 return prog.MakeVmaPointerArg(syzType, defAddrStart, length), a.Address255 }256 case *strace_types.Expression:257 addrStart := a.Eval(ctx.Target)258 return prog.MakeVmaPointerArg(syzType, defAddrStart, length), addrStart259 default:260 panic("Failed to parse mmap")261 }262}263func AddDependency(start, length uint64, addr prog.Arg, ctx *Context) {264 if mapping := ctx.State.Tracker.FindLatestOverlappingVMA(start); mapping != nil {265 dependsOn := make(map[*prog.Call]int, 0)266 dependsOn[mapping.GetCall()] = mapping.GetCallIdx()267 for _, dep := range mapping.GetUsedBy() {268 dependsOn[ctx.Prog.Calls[dep.Callidx]] = dep.Callidx269 }270 ctx.DependsOn[ctx.CurrentSyzCall] = dependsOn271 dep := tracker.NewMemDependency(len(ctx.Prog.Calls), addr, start, start+length)272 mapping.AddDependency(dep)273 }274}275func ParseLength(straceType strace_types.Type, ctx *Context) uint64 {276 switch a := straceType.(type) {277 case *strace_types.Expression:278 return a.Eval(ctx.Target)279 default:280 panic("Parsing Mmap length but type is not expression")281 }282}283func ParseFlags(syzType prog.Type, straceType strace_types.Type, ctx *Context, mapFlag bool) prog.Arg {284 switch a := straceType.(type) {285 case *strace_types.Expression:286 if mapFlag {287 val := a.Eval(ctx.Target) | GetFixedFlag(ctx)288 return prog.MakeConstArg(syzType, val)289 } else {290 return prog.MakeConstArg(syzType, a.Eval(ctx.Target))291 }292 default:293 panic("Parsing Flags")294 }295}296func ParseFd(syzType prog.Type, straceType strace_types.Type, ctx *Context) prog.Arg {297 if arg := ctx.Cache.Get(syzType, straceType); arg != nil {298 return prog.MakeResultArg(arg.Type(), arg.(*prog.ResultArg), arg.Type().Default())299 }300 switch a := straceType.(type) {301 case *strace_types.Expression:302 return prog.MakeResultArg(syzType, nil, a.Eval(ctx.Target))303 default:304 panic("Failed to Parse Fd because type is not Expression")305 }306}307func GetFixedFlag(ctx *Context) uint64 {308 callName := ctx.CurrentStraceCall.CallName309 if callName == "mmap" {310 return ctx.Target.ConstMap[MapFixed]311 }312 return ctx.Target.ConstMap[RemapFixed]313}...

Full Screen

Full Screen

vmaCallHandlers.go

Source:vmaCallHandlers.go Github

copy

Full Screen

...37 }38 ctx.CurrentSyzCall = call39 length := (parseLength(syscall.Args[1], ctx)/ctx.Target.PageSize + 1) * ctx.Target.PageSize //RoundUp PageSize40 log.Logf(3, "mmap call: %#v requires %d memory", syscall, length)41 addrArg, start := parseAddr(length, mmap.Args[0], syscall.Args[0], ctx)42 lengthArg := prog.MakeConstArg(mmap.Args[1], length)43 protArg := parseFlags(mmap.Args[2], syscall.Args[2], ctx, false)44 flagArg := parseFlags(mmap.Args[3], syscall.Args[3], ctx, true)45 fdArg := parseFd(mmap.Args[4], syscall.Args[4], ctx)46 call.Args = []prog.Arg{47 addrArg,48 lengthArg,49 protArg,50 flagArg,51 fdArg,52 prog.MakeConstArg(mmap.Args[5], 0),53 }54 //All mmaps have fixed mappings in syzkaller55 ctx.Tracker.createMapping(call, len(ctx.Prog.Calls), call.Args[0], start, start+length)56 return call57}58func parseMremap(mremap *prog.Syscall, syscall *parser.Syscall, ctx *Context) *prog.Call {59 call := &prog.Call{60 Meta: mremap,61 Ret: prog.MakeReturnArg(mremap.Ret),62 }63 ctx.CurrentSyzCall = call64 oldAddrArg, start := parseAddr(ctx.Target.PageSize, mremap.Args[0], syscall.Args[0], ctx)65 oldSz := parseLength(syscall.Args[1], ctx)66 newSz := parseLength(syscall.Args[2], ctx)67 oldSzArg := prog.MakeConstArg(mremap.Args[1], oldSz)68 newSzArg := prog.MakeConstArg(mremap.Args[2], newSz)69 flagArg := parseFlags(mremap.Args[3], syscall.Args[3], ctx, true)70 var destAddrArg prog.Arg71 var destAddr uint6472 if len(syscall.Args) > 4 {73 destAddrArg, destAddr = parseAddr(ctx.Target.PageSize, mremap.Args[4], syscall.Args[4], ctx)74 } else {75 straceAddrArg := parser.NewIntsType([]int64{syscall.Ret})76 destAddrArg, destAddr = parseAddr(ctx.Target.PageSize, mremap.Args[4], straceAddrArg, ctx)77 }78 addDependency(start, oldSz, oldAddrArg, ctx)79 call.Args = []prog.Arg{80 oldAddrArg,81 oldSzArg,82 newSzArg,83 flagArg,84 destAddrArg,85 }86 //All mmaps have fixed mappings in syzkaller87 ctx.Tracker.createMapping(call, len(ctx.Prog.Calls), call.Args[4], destAddr, destAddr+newSz)88 return call89}90func parseMsync(msync *prog.Syscall, syscall *parser.Syscall, ctx *Context) *prog.Call {91 var length uint6492 call := &prog.Call{93 Meta: msync,94 Ret: prog.MakeReturnArg(msync.Ret),95 }96 ctx.CurrentSyzCall = call97 addrArg, address := parseAddr(ctx.Target.PageSize, msync.Args[0], syscall.Args[0], ctx)98 length = parseLength(syscall.Args[1], ctx)99 lengthArg := prog.MakeConstArg(msync.Args[1], length)100 protArg := parseFlags(msync.Args[2], syscall.Args[2], ctx, false)101 addDependency(address, length, addrArg, ctx)102 call.Args = []prog.Arg{103 addrArg,104 lengthArg,105 protArg,106 }107 return call108}109func parseMprotect(mprotect *prog.Syscall, syscall *parser.Syscall, ctx *Context) *prog.Call {110 call := &prog.Call{111 Meta: mprotect,112 Ret: prog.MakeReturnArg(mprotect.Ret),113 }114 ctx.CurrentSyzCall = call115 addrArg, address := parseAddr(ctx.Target.PageSize, mprotect.Args[0], syscall.Args[0], ctx)116 length := parseLength(syscall.Args[1], ctx)117 lengthArg := prog.MakeConstArg(mprotect.Args[1], length)118 protArg := parseFlags(mprotect.Args[2], syscall.Args[2], ctx, false)119 addDependency(address, length, addrArg, ctx)120 call.Args = []prog.Arg{121 addrArg,122 lengthArg,123 protArg,124 }125 return call126}127func parseMunmap(munmap *prog.Syscall, syscall *parser.Syscall, ctx *Context) *prog.Call {128 call := &prog.Call{129 Meta: munmap,130 Ret: prog.MakeReturnArg(munmap.Ret),131 }132 ctx.CurrentSyzCall = call133 addrArg, address := parseAddr(ctx.Target.PageSize, munmap.Args[0], syscall.Args[0], ctx)134 length := parseLength(syscall.Args[1], ctx)135 lengthArg := prog.MakeConstArg(munmap.Args[1], length)136 addDependency(address, length, addrArg, ctx)137 call.Args = []prog.Arg{138 addrArg,139 lengthArg,140 }141 return call142}143func parseMadvise(madvise *prog.Syscall, syscall *parser.Syscall, ctx *Context) *prog.Call {144 call := &prog.Call{145 Meta: madvise,146 Ret: prog.MakeReturnArg(madvise.Ret),147 }148 ctx.CurrentSyzCall = call149 addrArg, address := parseAddr(ctx.Target.PageSize, madvise.Args[0], syscall.Args[0], ctx)150 length := parseLength(syscall.Args[1], ctx)151 lengthArg := prog.MakeConstArg(madvise.Args[1], length)152 var adviceArg prog.Arg153 switch a := syscall.Args[2].(type) {154 case parser.Expression:155 adviceArg = prog.MakeConstArg(madvise.Args[2], a.Eval(ctx.Target))156 default:157 log.Fatalf("Madvise advice arg is not expression")158 }159 addDependency(address, length, addrArg, ctx)160 call.Args = []prog.Arg{161 addrArg,162 lengthArg,163 adviceArg,164 }165 return call166}167func parseMlock(mlock *prog.Syscall, syscall *parser.Syscall, ctx *Context) *prog.Call {168 call := &prog.Call{169 Meta: mlock,170 Ret: prog.MakeReturnArg(mlock.Ret),171 }172 ctx.CurrentSyzCall = call173 addrArg, address := parseAddr(ctx.Target.PageSize, mlock.Args[0], syscall.Args[0], ctx)174 length := parseLength(syscall.Args[1], ctx)175 flagArg := prog.MakeConstArg(mlock.Args[1], length)176 addDependency(address, length, addrArg, ctx)177 call.Args = []prog.Arg{178 addrArg,179 flagArg,180 }181 return call182}183func parseMunlock(munlock *prog.Syscall, syscall *parser.Syscall, ctx *Context) *prog.Call {184 call := &prog.Call{185 Meta: munlock,186 Ret: prog.MakeReturnArg(munlock.Ret),187 }188 ctx.CurrentSyzCall = call189 addrArg, address := parseAddr(ctx.Target.PageSize, munlock.Args[0], syscall.Args[0], ctx)190 length := parseLength(syscall.Args[1], ctx)191 flagArg := prog.MakeConstArg(munlock.Args[1], length)192 addDependency(address, length, addrArg, ctx)193 call.Args = []prog.Arg{194 addrArg,195 flagArg,196 }197 return call198}199func parseShmat(shmat *prog.Syscall, syscall *parser.Syscall, ctx *Context) *prog.Call {200 /*201 * Shmat will create a shared memory map which we should track.202 * If the second argument is NULL then shmat will create the memory map and203 * store it at that address if successful.204 */205 shmid := uint64(0)206 var fd prog.Arg207 call := &prog.Call{208 Meta: shmat,209 Ret: prog.MakeReturnArg(shmat.Ret),210 }211 ctx.CurrentSyzCall = call212 if arg := ctx.ReturnCache.get(shmat.Args[0], syscall.Args[0]); arg != nil {213 switch a := arg.Type().(type) {214 case *prog.ResourceType:215 fd = prog.MakeResultArg(shmat.Args[0], arg.(*prog.ResultArg), a.Default())216 default:217 log.Fatalf("Expected first argument of Shmat to be resource type. Got: %s", a.Name())218 }219 } else {220 switch a := syscall.Args[0].(type) {221 case parser.Expression:222 shmid = a.Eval(ctx.Target)223 default:224 shmid = 0225 }226 fd = prog.MakeResultArg(shmat.Args[0], nil, shmid)227 }228 addrArg, address := parseAddr(ctx.Target.PageSize, shmat.Args[1], syscall.Args[1], ctx)229 flags := parseFlags(shmat.Args[2], syscall.Args[2], ctx, false)230 call.Args = []prog.Arg{231 fd,232 addrArg,233 flags,234 }235 //Cache the mapped address since it is a resource type as well236 call.Ret = prog.MakeReturnArg(shmat.Ret)237 straceRet := parser.NewIntsType([]int64{syscall.Ret})238 ctx.ReturnCache.cache(call.Ret.Type(), straceRet, call.Ret)239 length := uint64(4096)240 if req := ctx.Tracker.findShmRequest(shmid); req != nil {241 length = req.getSize()242 }243 ctx.Tracker.createMapping(call, len(ctx.Prog.Calls), call.Args[1], address, address+length)244 return call245}246func parseAddr(length uint64, syzType prog.Type, traceType parser.IrType, ctx *Context) (prog.Arg, uint64) {247 defAddrStart := (ctx.Target.NumPages - 2) * ctx.Target.PageSize248 switch a := traceType.(type) {249 case *parser.PointerType:250 var addrStart uint64251 if a.IsNull() {252 //Anonymous MMAP253 addrStart = uint64(ctx.CurrentStraceCall.Ret)254 return prog.MakeVmaPointerArg(syzType, defAddrStart, length), addrStart255 }256 return prog.MakeVmaPointerArg(syzType, defAddrStart, length), a.Address257 case parser.Expression:258 addrStart := a.Eval(ctx.Target)259 return prog.MakeVmaPointerArg(syzType, defAddrStart, length), addrStart260 default:...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

1package main2import (3 "fmt"4 "log"5 "os"6 "os/signal"7 "path"8 "syscall"9 "uiosample/ethdev"10 "uiosample/hugetlb"11 "uiosample/pci"12)13func main() {14 prog := path.Base(os.Args[0])15 if len(os.Args) < 3 {16 fmt.Printf("usage: %v <PCI ID> <PCI ID2>\n", prog)17 os.Exit(1)18 }19 hugetlb.SetPages(128)20 hugetlb.Init()21 addr1, err := pci.ParseAddr(os.Args[1])22 if err != nil {23 log.Fatal(err)24 }25 addr2, err := pci.ParseAddr(os.Args[2])26 if err != nil {27 log.Fatal(err)28 }29 port1, err := OpenPort(addr1)30 if err != nil {31 log.Fatal(err)32 }33 defer port1.Close()34 port2, err := OpenPort(addr2)35 if err != nil {36 log.Fatal(err)37 }38 defer port2.Close()39 s := NewServer(port1, port2)40 sig := make(chan os.Signal, 1)41 signal.Notify(sig, syscall.SIGTERM, syscall.SIGINT)42 s.Serve(sig)43 PrintCounters(port1.driver.CounterGroup())44 PrintCounters(port2.driver.CounterGroup())45 hugetlb.Stat()46}47func PrintCounter(name string, c ethdev.Counter) {48 if c == nil {49 return50 }51 fmt.Printf("%s: %v\n", name, c.Value())52}53func PrintCounters(g *ethdev.CounterGroup) {54 PrintCounter("RxPackets", g.RxPackets)55 PrintCounter("TxPackets", g.TxPackets)56 PrintCounter("RxOctets ", g.RxOctets)57 PrintCounter("TxOctets ", g.TxOctets)58 PrintCounter("RxMissed ", g.RxMissed)59 PrintCounter("RxErrors ", g.RxErrors)60 PrintCounter("TxErrors ", g.TxErrors)61 for name, c := range g.Ext {62 PrintCounter(name, c)63 }64}...

Full Screen

Full Screen

parseAddr

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if len(os.Args) != 2 {4 fmt.Fprintf(os.Stderr, "Usage: %s ip-addr5 os.Exit(1)6 }7 addr := net.ParseIP(name)8 if addr == nil {9 log.Fatal("Invalid address")10 }11 mask := addr.DefaultMask()12 network := addr.Mask(mask)13 ones, bits := mask.Size()14 fmt.Println("Address is ", addr.String(),15 "Mask is (hex) ", mask.String(),16 " Network is ", network.String())17 os.Exit(0)18}

Full Screen

Full Screen

parseAddr

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3}4import "fmt"5func main() {6}7import "fmt"8func main() {9}10import "fmt"11func main() {12}13import "fmt"14func main() {15}16import "fmt"17func main() {18}19import "fmt"20func main() {21}22import "fmt"23func main() {24}25import "fmt"26func main() {27}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful