Skip to content
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

Capturing NGAP messages #1160

Open
mrramachari opened this issue Mar 25, 2024 · 0 comments
Open

Capturing NGAP messages #1160

mrramachari opened this issue Mar 25, 2024 · 0 comments

Comments

@mrramachari
Copy link

mrramachari commented Mar 25, 2024

I wanted to capture ngap messages using this library,I wanted to know if that's possible using this library if yes I wanted some examples. So far I've managed to read sctp and gtp messages.

`package main
import (
	"fmt" // Import the fmt package to print messages to the console.
	"log" // Import the log package to log errors to the console.
	"os"

	"github.com/google/gopacket"        // Import the gopacket package to decode packets.
	"github.com/google/gopacket/layers" // Import the layers package to access the various network layers.
	"github.com/google/gopacket/pcap"   // Import the pcap package to capture packets.
)

func main() {
	// Check if file argument is provided
	if len(os.Args) < 2 {
		fmt.Println("Please provide a pcap file to read")
		os.Exit(1)
	}

	// Open up the pcap file for reading
	handle, err := pcap.OpenOffline(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	defer handle.Close()

	// Loop through packets in file
	packetSource := gopacket.NewPacketSource(handle, handle.LinkType())
	for packet := range packetSource.Packets() {

		// Print the packet details
		// fmt.Println(packet.String())

		// // Extract and print the Ethernet layer
		// ethLayer := packet.Layer(layers.LayerTypeEthernet)
		// if ethLayer != nil {
		// 	ethPacket, _ := ethLayer.(*layers.Ethernet)
		// 	fmt.Println("Ethernet source MAC address:", ethPacket.SrcMAC)
		// 	fmt.Println("Ethernet destination MAC address:", ethPacket.DstMAC)
		// }

		// // Extract and print the IP layer
		// ipLayer := packet.Layer(layers.LayerTypeIPv4)
		// if ipLayer != nil {
		// 	ipPacket, _ := ipLayer.(*layers.IPv4)
		// 	fmt.Println("IP source address:", ipPacket.SrcIP)
		// 	fmt.Println("IP destination address:", ipPacket.DstIP)
		// }

		// Extract and check for SCTP layer
		sctpLayer := packet.Layer(layers.LayerTypeSCTP)
		if sctpLayer != nil {
			fmt.Println("SCTP Packet:")
			fmt.Println(packet.String())
			continue // Skip further processing for this packet
		}

		
		// // Extract and check for GTP layer
		// gtpLayer := packet.Layer(layers.LayerTypeGTP)
		// if gtpLayer != nil {
		// 	fmt.Println("GTP Packet:")
		// 	fmt.Println(packet.String())
		// 	continue // Skip further processing for this packet
		// }
		ngapLayer := packet.Layer(layers.LayerTypeGTPv1U)
		if ngapLayer != nil {
			fmt.Println("GTPv1U Message:")
			fmt.Println(packet.String())
			continue // Skip further processing for this packet
		}
	}
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant