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

Does go-gtp allow to create the GTP headers? #143

Closed
vggonzalez opened this issue Jan 12, 2021 · 2 comments
Closed

Does go-gtp allow to create the GTP headers? #143

vggonzalez opened this issue Jan 12, 2021 · 2 comments

Comments

@vggonzalez
Copy link

Hi!

I need to go through an already established GTP tunnel. To do so, I need to create the GTP header. I was wondering if your project has any kind of facilities for it. I've been looking through it and so far I couldn't find any or a similar example.

Regards,
Víctor

@wmnsk
Copy link
Owner

wmnsk commented Jan 12, 2021

You can create the packet with message.NewTPDU and marshal it into a binary with Marshal(). Then you can write it to UDP conn.

import "github.com/wmnsk/go-gtp/gtpv1/message"

msg := message.NewTPDU(teid, payload)

b, err := msg.Marshal()
if err := nil {
    // ...
}

if _, err := conn.WriteTo(b, raddr); err := nil {
    // ...
}

If you need to set values to more fields in GTPv1 header(other than TEID), create the message from Header struct by yourself instead.

// Header is a GTPv1 common header.
type Header struct {
Flags uint8
Type uint8
Length uint16
TEID uint32
SequenceNumber uint16
Reserved uint16
Payload []byte
}

msg := &message.Header{
   // ...
}

Hope this helps.

@wmnsk
Copy link
Owner

wmnsk commented Jan 26, 2021

@vggonzalez
Let me know when you need more help.

@wmnsk wmnsk closed this as completed Jan 26, 2021
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

2 participants