CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Hybrid View

  1. #1
    Join Date
    May 2013

    UDP bind to define which source port to use

    Hi. I am trying to define which source port my program will use to send a packet from. I am able to define which port to send to, but not from. I'm sure it is possible but I don't know what exactly to do.

    Here is what I have on my program:

    sin.sin_addr.s_addr = *(LPDWORD)gethostbyname((char *)s_uf.m_szHost)->h_addr_list[0];
    sin.sin_family = AF_INET;
    sin.sin_port = htons(s_uf.m_nPort);
    sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    if (sock == SOCKET_ERROR)

    The "sin.sin_addr.s_addr" is so I can define which address to send the packet to and "sin.sin_port" is for me to define which port I can send the packet to.

    Can someone please give me a code I can use so I can define which source port I can use to send packet from? I have the .cpp if anyone needs it.

    Attached Files Attached Files
    Last edited by marco712; June 24th, 2013 at 09:59 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.