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

Need help understanding RecvMsg #269

Open
espoal opened this issue Apr 5, 2024 · 0 comments
Open

Need help understanding RecvMsg #269

espoal opened this issue Apr 5, 2024 · 0 comments

Comments

@espoal
Copy link

espoal commented Apr 5, 2024

I'm trying to build an example io_uring echo udp server here. Basically since recv_from is not available, I need to use recvmsg and somehow retrieve the source address to respond.

My first question is why this work:

let mut msg_hdr: libc::msghdr = unsafe { std::mem::zeroed() };
// I copied this from tokio/io-uring test code, I don't know why it works
// https://github.com/tokio-rs/io-uring/blob/master/io-uring-test/src/tests/net.rs
msg_hdr.msg_namelen = 16;

If I set msg_namelen to anything but 0 and 16 then I get parsing errors. If I set to 0 the msghdr is always empty (excpet the payload size). If I set to 16 then I get some data like:

msg_out: RecvMsgOut { header: io_uring_recvmsg_out { namelen: 16, controllen: 0, payloadlen: 5, flags: 0 }, msghdr_name_len: 16, name_data: [2, 0, 129, 54, 127, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], control_data: [], payload_data: [107, 107, 107, 107, 10] }
payload: "kkkk\n"
buffer: [16, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 2, 0, 129, 54, 127, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 107, 107, 107, 107, 10]
name_data: [2, 0, 129, 54, 127, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]

But I don't know how to interpret this. How do I use this data to create a file descriptor for SendMsg?
Should I maybe set somehow the IP_PKTINFO flag?

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