Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8196023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:20:24+00:00 2026-06-07T05:20:24+00:00

How do I obtain the underlying syscall.Handle for a *net.UDPConn on Windows? I want

  • 0

How do I obtain the underlying syscall.Handle for a *net.UDPConn on Windows? I want this handle to set the IP_MULTICAST_TTL via syscall.SetsockoptInt. On Linux I do the following:

func setTTL(conn *net.UDPConn, ttl int) error {
    f, err := conn.File()
    if err != nil {
        return err
    }
    defer f.Close()
    fd := int(f.Fd())
    return syscall.SetsockoptInt(fd, syscall.SOL_IP, syscall.IP_MULTICAST_TTL, ttl)
}

But on Windows, the implicit dup inside *net.UDPConn‘s File() fails with:

04:24:49 main.go:150: dup: not supported by windows

And in the source code is marked as a to-do. How can I get this handle? Is there some other way to set the TTL if not?

Update0

I’ve submitted the shortcomings to the Go issue tracker:

  • SetTTL for *net.UDPConn
  • Implement dup for netFD on Windows
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:20:27+00:00Added an answer on June 7, 2026 at 5:20 am

    The short answer is impossible. But since that isn’t an answer you want to hear, I will give you the right way and wrong way to solve the problem.

    The right way:

    1. implement dup() for Windows.
    2. submit to Go as a changeset
    3. wait for it to be released to use it

    Obviously the right way has some issues… but I highly recommend doing it. Go needs windows developers to fix up these types of serious problems. The only reason this can’t be done in Windows is no one implemented the function

    The wrong way:

    Until the patch you write gets accepted and released, you can fake it through unsafe. The way the following code works by mirroring the exact structure of a net.UDPConn. This included copying over all structs from net that make up a UDPConn. Then unsafe is used to assert that the local UDPConn is the same as net’s UDPConn. The compiler can not check this and takes your word for it. Were the internals of net to ever change, it would compile but god knows what it would do.

    All code is untested.

    package reallyunsafenet
    
    import (
            "net"
            "sync"
            "syscall"
            "unsafe"
    )
    
    // copied from go/src/pkg/net/fd_windows.go
    type ioResult struct {
            qty uint32
            err error
    }
    
    // copied from go/src/pkg/net/fd_windows.go
    type netFD struct {
            // locking/lifetime of sysfd
            sysmu   sync.Mutex
            sysref  int
            closing bool
    
            // immutable until Close
            sysfd       syscall.Handle
            family      int
            sotype      int
            isConnected bool
            net         string
            laddr       net.Addr
            raddr       net.Addr
            resultc     [2]chan ioResult
            errnoc      [2]chan error
    
            // owned by client
            rdeadline int64
            rio       sync.Mutex
            wdeadline int64
            wio       sync.Mutex
    }
    
    // copied from go/src/pkg/net/udpsock_posix.go
    type UDPConn struct {
        fd *netFD
    }
    
    // function to get fd
    func GetFD(conn *net.UDPConn) syscall.Handle {
            c := (*UDPConn)(unsafe.Pointer(conn))
            return c.fd.sysfd
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to do something like this: <c:set var=strDate value=<fmt:formatDate value='${obj.dateIn}' pattern='ddMMyyyy'/>/> to obtain
I want obtain full URL adres in php script, tell please, this code always
I want to obtain last links from specific user account. I use this code:
I want obtain the relations with two tables. This is my schema.yml Oferta: columns:
How can I obtain the count of faulted messages from a Windows Azure Storage
I need to obtain a Date object from this String:This is a example) M-27\nJUN-2012
Friends, This Ask Tom thread which I found via another SO question, mentions Table
Using php-sdk I obtain pages in this way: $array = $this->instance->api( '/' . $fb_user
I can't obtain the result I want, let me explain: I have two tables
I need to obtain the final url for an image to set it as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.