473,383 Members | 1,822 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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:

Expand|Select|Wrap|Line Numbers
  1.         sin.sin_addr.s_addr = *(LPDWORD)gethostbyname((char *)s_uf.m_szHost)->h_addr_list[0];
  2.         sin.sin_family = AF_INET;
  3.         sin.sin_port = htons(s_uf.m_nPort);
  4.         sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  5.     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.

Thanks
Jun 24 '13 #1
0 9619

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Alexander N. Spitzer | last post by:
If I have a machine with 3 virtual IP addresses (192.168.1.), how can I start 3 instances of the same RMI application (each started with different properties/configs), each listening on the port...
4
by: Pif Paf | last post by:
I am writing programs that will run as TCP servers. Briefly, I want to set up a TCP server on a port in such a way that if another server is already sitting on that port (both servers are Python...
5
by: Alex Polite | last post by:
If I try to bind a socket to a port that's already in use I get this error "error socket.error: (98, 'Address already in use')" Is there anyway to check in advance if a port i already taken? ...
1
by: Jabadia | last post by:
Hi , I would like to know if it is possible to 'build' the TCP header with Source port / destination port , and with FLAGs i.e. SYN flag , sequence etc. I know this can be done in C++ of course...
0
by: Gregory Hassett | last post by:
Hello, I want to periodically send a TCP packet to a peer, always from the same source port. That is, each packet will come from my local ip address, port 8801, and go to the peer's ip address,...
3
by: Franky | last post by:
I need to specify a range of outgoing port numbers (i.e., 20000-21000). Is there any way to bind this range so that when system picks up a free port, it will only pick one from this range? I know I...
3
by: Sells, Fred | last post by:
I'm using MSW XP Pro with Python 2.4 to develop but production will be Linux with Python 2.3. (could upgrade to 2.4 if absolutely necessary) I can also switch to Linux for development if...
25
by: bmearns | last post by:
Is it possible to specify which port to use as the outbound port on a connection? I have the IP address and port number for the computer I'm trying to connect to (not listening for), but it's...
3
by: Maksim Kasimov | last post by:
Hi, how to set source ip-address when do __socket.connect((host, port)) on a machine that have a several ip-adresses? many thanks for advice. __socket = socket.socket(socket.AF_INET,...
4
by: slaskbrev1 | last post by:
Hi. Im sending data over a SOCK_DGRAM socket, is it possible to define what source port my program will use? I guess one alternative is to craft the UDP header by myself, what type of socket...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.